diff options
author | andy <andy@whiskeymedia.com> | 2013-04-22 12:43:40 -0700 |
---|---|---|
committer | andy <andy@whiskeymedia.com> | 2013-04-22 12:43:40 -0700 |
commit | 1cb44f26d89455032fe2bd42d6a0a405296a4bf2 (patch) | |
tree | 48c5569665b60d54989f1aa61c76fd15cd625cf9 /redis/client.py | |
parent | fb747ed0d63e3661892942457aa25a0b8bfede1f (diff) | |
download | redis-py-1cb44f26d89455032fe2bd42d6a0a405296a4bf2.tar.gz |
added PSETEX
Diffstat (limited to 'redis/client.py')
-rw-r--r-- | redis/client.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/redis/client.py b/redis/client.py index 8b4305a..7f37c14 100644 --- a/redis/client.py +++ b/redis/client.py @@ -183,7 +183,7 @@ class StrictRedis(object): RESPONSE_CALLBACKS = dict_merge( string_keys_to_dict( 'AUTH DEL EXISTS EXPIRE EXPIREAT HDEL HEXISTS HMSET MOVE MSETNX ' - 'PERSIST RENAMENX SISMEMBER SMOVE SETEX SETNX ZREM', + 'PERSIST PSETEX RENAMENX SISMEMBER SMOVE SETEX SETNX ZREM', bool ), string_keys_to_dict( @@ -665,6 +665,17 @@ class StrictRedis(object): when = int(mod_time.mktime(when.timetuple())) * 1000 + ms return self.execute_command('PEXPIREAT', name, when) + def psetex(self, name, time_ms, value): + """ + Set the value of key ``name`` to ``value`` that expires in ``time_ms`` + milliseconds. ``time_ms`` can be represented by an integer or a Python + timedelta object + """ + if isinstance(time_ms, datetime.timedelta): + ms = int(time_ms.microseconds / 1000) + time_ms = time_ms.seconds + time_ms.days * 24 * 3600 * 1000 + ms + return self.execute_command('PSETEX', name, time_ms, value) + def pttl(self, name): "Returns the number of milliseconds until the key ``name`` will expire" return self.execute_command('PTTL', name) @@ -706,13 +717,6 @@ class StrictRedis(object): time = time.seconds + time.days * 24 * 3600 return self.execute_command('SETEX', name, time, value) - def psetex(self, name, time_ms, value): - """ - Set the value of key ``name`` to ``value`` that expires in ``time_ms`` - milliseconds. - """ - return self.execute_command('PSETEX', name, time_ms, value) - def setnx(self, name, value): "Set the value of key ``name`` to ``value`` if key doesn't exist" return self.execute_command('SETNX', name, value) |