// Redis error reference

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
카테고리
Data types and commands
오류 메시지
ERR invalid expire time in 'set' command

의미

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.

일반적인 원인

  • 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

해결 방법

  1. 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
  2. Guard computed TTLs before the call, and skip the command entirely when the intent was 'no expiry'.

  3. 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.

안전하게 재현하세요

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

질문

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.

관련 오류

More data types and commands errors

코드와 메시지 텍스트의 출처는 다음과 같습니다 Redis documentation and source code. 전체 목록은 Redis error list 또는 모든 데이터베이스 오류 검색.

// 오류는 줄이고, 수정은 빠르게

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.

이 페이지의 텍스트와 데이터: CC BY 4.0, 출처: SQLly (sqlly.app). 코드와 SQL 스니펫: MIT. 라이선스 세부 정보 인용된 오류 메시지 텍스트의 권리는 해당 데이터베이스 공급업체에 있습니다.