From 9e893764169e88e090695ac06f3c04cea0ce81ca Mon Sep 17 00:00:00 2001 From: Samuel Dion-Girardeau Date: Sun, 23 Oct 2016 03:11:32 -0400 Subject: [PATCH] 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. --- snappass/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/snappass/main.py b/snappass/main.py index a4b489d..04e0ef6 100644 --- a/snappass/main.py +++ b/snappass/main.py @@ -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