summaryrefslogtreecommitdiff
path: root/redis/commands.py
diff options
context:
space:
mode:
authorAvital Fine <79420960+AvitalFineRedis@users.noreply.github.com>2021-09-01 11:44:28 +0300
committerGitHub <noreply@github.com>2021-09-01 11:44:28 +0300
commitde9922ad0fc955668d99748f3ad3be0ccff1f9da (patch)
tree80431770b019dd7511fc95d7ccb30e61ed604060 /redis/commands.py
parentefdba1a77a2755c70ba9754aa592dde8c8c50217 (diff)
downloadredis-py-de9922ad0fc955668d99748f3ad3be0ccff1f9da.tar.gz
Adding EXAT and PXAT (unix time support) support for SET (#1547)
* set in unix time * update skip version
Diffstat (limited to 'redis/commands.py')
-rw-r--r--redis/commands.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/redis/commands.py b/redis/commands.py
index 29877db..2d39f5d 100644
--- a/redis/commands.py
+++ b/redis/commands.py
@@ -1014,7 +1014,8 @@ class Commands:
return self.execute_command('RESTORE', *params)
def set(self, name, value,
- ex=None, px=None, nx=False, xx=False, keepttl=False, get=False):
+ ex=None, px=None, nx=False, xx=False, keepttl=False, get=False,
+ exat=None, pxat=None):
"""
Set the value at key ``name`` to ``value``
@@ -1034,6 +1035,12 @@ class Commands:
``get`` if True, set the value at key ``name`` to ``value`` and return
the old value stored at key, or None when key did not exist.
(Available since Redis 6.2)
+
+ ``exat`` sets an expire flag on key ``name`` for ``ex`` seconds,
+ specified in unix time.
+
+ ``pxat`` sets an expire flag on key ``name`` for ``ex`` milliseconds,
+ specified in unix time.
"""
pieces = [name, value]
options = {}
@@ -1047,15 +1054,26 @@ class Commands:
if isinstance(px, datetime.timedelta):
px = int(px.total_seconds() * 1000)
pieces.append(px)
+ if exat is not None:
+ pieces.append('EXAT')
+ if isinstance(exat, datetime.datetime):
+ s = int(exat.microsecond / 1000000)
+ exat = int(time.mktime(exat.timetuple())) + s
+ pieces.append(exat)
+ if pxat is not None:
+ pieces.append('PXAT')
+ if isinstance(pxat, datetime.datetime):
+ ms = int(pxat.microsecond / 1000)
+ pxat = int(time.mktime(pxat.timetuple())) * 1000 + ms
+ pieces.append(pxat)
+ if keepttl:
+ pieces.append('KEEPTTL')
if nx:
pieces.append('NX')
if xx:
pieces.append('XX')
- if keepttl:
- pieces.append('KEEPTTL')
-
if get:
pieces.append('GET')
options["get"] = True