ask/celery — Issue #606: use atomic SETEX operation in redis backend
Author: yaniv-aknin
Created: 2012-02-07 10:22:33+00:00
State: open

Ran into this tidbit in [backens/redis.py](https://github.com/ask/celery/blob/master/celery/backends/redis.py#L72):

def set(self, key, value):
client = self.client
client.set(key, value)
if self.expires is not None:
client.expire(key, self.expires)
client.publish(key, value)

Seems to me like a peculiar way to do things. Why not use Redis' explicit SETEX (set-and-expire) atomic operation, and avoid the risk of a memory leak if connectivity is lost after the SET and before the EXPIRE?

I guess I could make a proper pull request for this, but it's such a trifle that setting up the test environment and running the suite would probably take longer than actually making the change. If a current contributor with a properly setup environment and all would like to take ownership of this, I think all it would take is (*I never ran this code!*):

def set(self, key, value):
if self.expires is not None:
self.client.setex(key, self.expires, value)
else:
self.client.set(key, value)
self.client.publish(key, value)

Thanks!