ERR
RedisERRORNotableCommand ErrorHIGH confidence

Invalid expire time in command

Production Risk

Low. The server correctly rejects an invalid argument.

What this means

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.

Why it happens
  1. 1Providing a non-integer string as the expiry time (e.g., '1.5', 'abc').
  2. 2A bug in application logic that calculates a negative duration.
  3. 3Passing a floating-point number from a language where it is not automatically truncated to an integer before being sent to Redis.
How to reproduce

A client attempts to set an expiration on a key using a non-integer value.

trigger — this will error
trigger — this will error
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

Provide a valid positive integer for the timeout
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

Sanitize and validate input in the application
// 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.

What not to do

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.

Sources
Official documentation ↗

Command argument parsing for expiration commands.

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Redis errors