{
  "id": "redis/key-expiry-race-condition",
  "signature": "ERR Key expiry race condition: TTL updated but key already expired",
  "signature_zh": "键过期竞态条件：TTL 已更新但键已过期",
  "regex": "ERR Key expiry race condition: TTL updated but key already expired",
  "domain": "redis",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A race condition occurred when multiple clients simultaneously update TTL and key value, causing the key to expire before the TTL update takes effect.",
  "root_cause_type": "generic",
  "root_cause_zh": "多个客户端同时更新 TTL 和键值时发生竞态条件，导致键在 TTL 更新生效前已过期。",
  "versions": [
    {
      "version": "6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "7.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "SET with EX still has a race if key is deleted by another client before EXPIRE.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Redis transactions are not atomic for conditional operations; EXPIRE may still fail if key expires during transaction.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Race condition persists; repeated failures under high concurrency.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use EVAL with a script: 'local val = redis.call(\"GET\", KEYS[1]); if val then redis.call(\"SET\", KEYS[1], ARGV[1]); redis.call(\"EXPIRE\", KEYS[1], ARGV[2]); return 1 else return 0 end'.",
      "success_rate": 0.95,
      "how": "Use EVAL with a script: 'local val = redis.call(\"GET\", KEYS[1]); if val then redis.call(\"SET\", KEYS[1], ARGV[1]); redis.call(\"EXPIRE\", KEYS[1], ARGV[2]); return 1 else return 0 end'.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use WATCH on the key before GET, then MULTI/EXEC to update TTL. If WATCH triggers, retry.",
      "success_rate": 0.85,
      "how": "Use WATCH on the key before GET, then MULTI/EXEC to update TTL. If WATCH triggers, retry.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用 EVAL 执行脚本：'local val = redis.call(\"GET\", KEYS[1]); if val then redis.call(\"SET\", KEYS[1], ARGV[1]); redis.call(\"EXPIRE\", KEYS[1], ARGV[2]); return 1 else return 0 end'。",
    "在 GET 前使用 WATCH 监视键，然后使用 MULTI/EXEC 更新 TTL。如果 WATCH 触发，则重试。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://redis.io/docs/latest/commands/expire/",
  "official_doc_section": null,
  "error_code": "ERM",
  "verification_tier": "ai_generated",
  "confidence": 0.8,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-11-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}