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

2

5

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

Gilud answered 17/12, 2017 at 15:45 Comment(0)
G
8

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.

Gilud answered 17/12, 2017 at 15:45 Comment(1)
the solution can be found in here as well: github.com/andymccurdy/redis-py/issues/260Gilud
Y
2

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.

Yeargain answered 27/12, 2021 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.