Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis - setex - value is not an integer or out of range

Tags:

redis

The following used to work fine:

redis_client.setex(key, expiry_in_sec, value_json)

And now it suddenly returns:

value is not an integer or out of range

like image 695
Amit Talmor Avatar asked Dec 17 '17 15:12

Amit Talmor


2 Answers

The issue is between the different redis clients.

When working with StrictRedis, the setex syntax is:

setex key, expiry, value

When working with Redis client, the setex syntax is:

setex key, value, expiry

our specific problem was that someone changed the redis client.

like image 94
Amit Talmor Avatar answered Jan 01 '23 02:01

Amit Talmor


Redis will also return this error if the time value (or expiration time) is a float instead of an int.

In my case, using Redis in Python, I had to change the following:

Causes Error

ex = expiration_delta.total_seconds()

Fixed

ex = int(expiration_delta.total_seconds())

success = redis.set(name=redis_key, value=my_val, ex=ex, nx=True)

Note the ex argument to set() makes it work like setex.

like image 40
Christopher Peisert Avatar answered Jan 01 '23 02:01

Christopher Peisert