summaryrefslogtreecommitdiff
path: root/redis/client.py
diff options
context:
space:
mode:
authorJon Parise <jon@indelible.org>2012-06-26 15:29:00 -0700
committerJon Parise <jon@indelible.org>2012-06-26 15:29:00 -0700
commita72d0c19d6db6c5ef427cdf83e6f7639b21bae74 (patch)
treebb50978a4bb2937edd5b8e3a206fe9a28c9600b4 /redis/client.py
parent169bf49c2b6146b55fdb0e3f9728d5c2b41ac8d0 (diff)
downloadredis-py-a72d0c19d6db6c5ef427cdf83e6f7639b21bae74.tar.gz
expire() and setex() now accept timedelta objects.
This mimics the datetime support provided by `expireat()`.
Diffstat (limited to 'redis/client.py')
-rw-r--r--redis/client.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/redis/client.py b/redis/client.py
index 78ef51f..d866928 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -413,7 +413,12 @@ class StrictRedis(object):
__contains__ = exists
def expire(self, name, time):
- "Set an expire flag on key ``name`` for ``time`` seconds"
+ """
+ Set an expire flag on key ``name`` for ``time`` seconds. ``time``
+ can be represented by an integer or a Python timedelta object.
+ """
+ if isinstance(time, datetime.timedelta):
+ time = int(time.total_seconds())
return self.execute_command('EXPIRE', name, time)
def expireat(self, name, when):
@@ -524,9 +529,12 @@ class StrictRedis(object):
def setex(self, name, time, value):
"""
- Set the value of key ``name`` to ``value``
- that expires in ``time`` seconds
+ Set the value of key ``name`` to ``value`` that expires in ``time``
+ seconds. ``time`` can be represented by an integer or a Python
+ timedelta object.
"""
+ if isinstance(time, datetime.timedelta):
+ time = int(time.total_seconds())
return self.execute_command('SETEX', name, time, value)
def setnx(self, name, value):
@@ -1147,9 +1155,12 @@ class Redis(StrictRedis):
def setex(self, name, value, time):
"""
- Set the value of key ``name`` to ``value``
- that expires in ``time`` seconds
+ Set the value of key ``name`` to ``value`` that expires in ``time``
+ seconds. ``time`` can be represented by an integer or a Python
+ timedelta object.
"""
+ if isinstance(time, datetime.timedelta):
+ time = int(time.total_seconds())
return self.execute_command('SETEX', name, time, value)
def lrem(self, name, value, num=0):