0

We run a Python (Django) application that temporarily stores data in Redis. Sometimes though it happens that data by the time it gets to get stored in Redis is already expired and therefore setex is called with an expiration time of <= 0.

Is there a way to make Redis silently discard such a setex command without openly complaining with:

 ResponseError: invalid expire time in setex

Right now I cannot do that from the application.

2 Answers 2

1

Django has very good primitives for handling this situation. Just set up redis as one of your CACHES and use the cachr.set method to set an expiration n seconds from time of storage.

0

You can write a LUA script that does that.

Send the key name as KEYS, and value string and expiration as ARGV:

redis.call('set', KEYS[1], ARGV[1],'EX', ARGV[2])
return 1

You can also call set only if expiration > 0. You can return any answer you want, regardless of the operation made.

Load you LUA script once with SCRIPT LOAD, save its SHA1 answer, and use it with EVALSHA to avoid sending/compiling the lua script for every usage.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .