ERR invalid expire time: Expire value is out of range
The command accepted a TTL option but the number with it is not valid: it must be a positive integer within the supported range.
- Error prefix
ERR invalid expire time- Kategorie
- Data types and commands
Was es bedeutet
Commands that can expire a key, such as SET with EX, PX, EXAT or PXAT, EXPIRE, PEXPIRE, EXPIREAT and GETEX, validate the TTL before doing anything. A zero, a negative number, or a timestamp far outside the representable range produces this error with the command named, and the key is left untouched.
Two shapes of mistake dominate. A computed TTL that resolved to 0 or negative, where the code meant 'no expiry' and passed it straight through. And confusing relative with absolute: EX takes seconds from now, EXAT takes a unix timestamp. Handing a timestamp to EX does not error; it sets a TTL decades out, so the symptom is a key that never expires.
Häufige Ursachen
- A computed TTL resolved to 0 or negative, for example a deadline that was already in the past.
- An absolute unix timestamp was passed to the relative option, EX instead of EXAT or the reverse.
- The client sent the TTL in the wrong form, such as the string 60s or a nil value.
Find the cause
SET session:abc data EX 0 # (error) ERR invalid expire time in 'set' command - the check itself TTL session:abc # The key is unchanged: -1 (no TTL) or -2 (missing) TIME # The server clock, for computing EXAT values
Wie du es behebst
-
Check the value and unit at the call site; relative options need positive integers:
SET session:abc data EX 3600 # 3600 seconds from now SET session:abc data EXAT 1798761600 # absolute unix timestamp
-
Guard computed TTLs before the call, and skip the command entirely when the intent was 'no expiry'.
-
When the intent is 'keep the existing TTL', say so instead of recomputing it:
SET session:abc newdata KEEPTTL
Other ways to handle it
Centralize TTL computation in one client helper so every expiry goes through the same validation, and prefer EXPIRE after the write when the TTL comes from a later decision. KEEPTTL replaces most recomputation of existing expiries.
Sicher reproduzieren
redis-cli SET session:abc data EX 0 # (error) ERR invalid expire time in 'set' command redis-cli SET session:abc data EX 60 # OK redis-cli TTL session:abc # (integer) 60 or a little less
Fragen
Does EX 0 delete the key immediately?
No, SET rejects it before anything happens. To expire on purpose, use EXPIRE, which treats a non-positive TTL as 'delete now', while SET's EX option validates instead.
Is the timestamp in seconds or milliseconds?
EX and EXAT are seconds; PX and PXAT are milliseconds. Mixing the two does not raise this error; it sets the wrong expiry silently, so read TTL or PTTL after the write to confirm.
Zugehörige Fehler
ERR wrong number of argumentsArgument count is wrong22003PostgreSQL: numerischer Wert außerhalb des zulässigen Bereichs1264MySQL: Wert für Spalte außerhalb des zulässigen Bereichs
More data types and commands errors
WRONGTYPEThe key holds a different data typeERR unknown commandRedis does not know this commandNOSCRIPTScript SHA1 is not cachedEXECABORTTransaction discarded after an errorBUSYServer is blocked by a long script
Der Code und der Meldungstext stammen aus der Redis documentation and source code. Durchstöbere die vollständige Redis error list oder Jeden Datenbankfehler durchsuchen.
Work on Redis in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for Redis and the other databases you use.
Text und Daten auf dieser Seite: CC BY 4.0, Quelle: SQLly (sqlly.app). Code und SQL-Snippets: MIT. Lizenzdetails Zitierte Fehlermeldungstexte gehören dem jeweiligen Datenbankhersteller.