summaryrefslogtreecommitdiff
path: root/redis/client.py
diff options
context:
space:
mode:
authorlaixintao <laixintaoo@gmail.com>2020-03-10 12:04:36 +0800
committerAndy McCurdy <andy@andymccurdy.com>2020-03-12 11:02:10 -0700
commitb9544af2c8eb85fcbe11137e6b0797066e3d718f (patch)
treec0921cf60bd792bbcb8f2fd6df422c33c7961f53 /redis/client.py
parent9c8be70e12c501dd0682232e9a7b686ac5e70ec3 (diff)
downloadredis-py-b9544af2c8eb85fcbe11137e6b0797066e3d718f.tar.gz
add keepttl option to set command.
fixes #1304 fixes #1280
Diffstat (limited to 'redis/client.py')
-rwxr-xr-xredis/client.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/redis/client.py b/redis/client.py
index 9f75465..1393a1c 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -1761,7 +1761,8 @@ class Redis(object):
params.append('REPLACE')
return self.execute_command('RESTORE', *params)
- def set(self, name, value, ex=None, px=None, nx=False, xx=False):
+ def set(self, name, value,
+ ex=None, px=None, nx=False, xx=False, keepttl=False):
"""
Set the value at key ``name`` to ``value``
@@ -1774,6 +1775,9 @@ class Redis(object):
``xx`` if set to True, set the value at key ``name`` to ``value`` only
if it already exists.
+
+ ``keepttl`` if True, retain the time to live associated with the key.
+ (Available since Redis 6.0)
"""
pieces = [name, value]
if ex is not None:
@@ -1791,6 +1795,10 @@ class Redis(object):
pieces.append('NX')
if xx:
pieces.append('XX')
+
+ if keepttl:
+ pieces.append('KEEPTTL')
+
return self.execute_command('SET', *pieces)
def __setitem__(self, name, value):