Invalid expire time in command
Production Risk
Low. The server correctly rejects an invalid argument.
This error is returned by commands that set an expiration (like EXPIRE, PEXPIRE, SET with EX/PX options) when the provided time argument is not a valid integer or is a negative value.
- 1Providing a non-integer string as the expiry time (e.g., '1.5', 'abc').
- 2A bug in application logic that calculates a negative duration.
- 3Passing a floating-point number from a language where it is not automatically truncated to an integer before being sent to Redis.
A client attempts to set an expiration on a key using a non-integer value.
SET mykey "some value" EXPIRE mykey 10.5
expected output
(error) ERR value is not an integer or out of range
Fix 1
Provide a valid positive integer for the timeout
WHEN When setting an expiry time
SET mykey "some value" EXPIRE mykey 10
Why this works
The expiration commands strictly require a positive integer representing seconds (EXPIRE), milliseconds (PEXPIRE), or a Unix timestamp (EXPIREAT/PEXPIREAT).
Fix 2
Sanitize and validate input in the application
WHEN Before sending the command to Redis
// Pseudocode
let seconds = Math.floor(untrusted_input);
if (seconds > 0) {
redis.expire("mykey", seconds);
}Why this works
Your application code should be responsible for ensuring that the value passed to the Redis client is a valid, positive integer.
✕ Send a negative value to try to delete a key
This causes an error. To delete a key, use the `DEL` command. A zero or negative expiry is treated as an expired key and may cause immediate deletion, but `DEL` is the explicit and correct way.
Command argument parsing for expiration commands.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev