Set password value and expiration atomically

Redis has a `SETEX` (http://redis.io/commands/SETEX) method,
which does both setting the value and setting the expiration
atomically.
This commit is contained in:
Samuel Dion-Girardeau 2016-10-23 03:11:32 -04:00
parent d12a090952
commit 9e89376416

View file

@ -48,8 +48,7 @@ def check_redis_alive(fn):
@check_redis_alive
def set_password(password, ttl):
key = uuid.uuid4().hex
redis_client.set(key, password)
redis_client.expire(key, ttl)
redis_client.setex(key, ttl, password)
return key