summaryrefslogtreecommitdiff
path: root/redis/commands/core.py
diff options
context:
space:
mode:
authordogukanteber <47397379+dogukanteber@users.noreply.github.com>2022-03-14 16:03:28 +0300
committerGitHub <noreply@github.com>2022-03-14 15:03:28 +0200
commitf43c3e08ab0facf5a2d70bcd91365faf74d7e220 (patch)
treeea847459c7852a67111e232a819be788a95ecfb0 /redis/commands/core.py
parenteac3a34d162aa83c3094cbab80d535ca92fdf972 (diff)
downloadredis-py-f43c3e08ab0facf5a2d70bcd91365faf74d7e220.tar.gz
Add support for PEXPIRE command's option (#2026)
* Add support for PEXPIRE command's option * Alter method arguments * add variables to the function header Co-authored-by: dvora-h <dvora.heller@redis.com>
Diffstat (limited to 'redis/commands/core.py')
-rw-r--r--redis/commands/core.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/redis/commands/core.py b/redis/commands/core.py
index 5b6d42b..7e3514e 100644
--- a/redis/commands/core.py
+++ b/redis/commands/core.py
@@ -1827,17 +1827,41 @@ class BasicKeyCommands(CommandsProtocol):
"""
return self.execute_command("PERSIST", name)
- def pexpire(self, name: KeyT, time: ExpiryT) -> ResponseT:
+ def pexpire(
+ self,
+ name: KeyT,
+ time: ExpiryT,
+ nx: bool = False,
+ xx: bool = False,
+ gt: bool = False,
+ lt: bool = False,
+ ) -> ResponseT:
"""
- Set an expire flag on key ``name`` for ``time`` milliseconds.
- ``time`` can be represented by an integer or a Python timedelta
- object.
+ Set an expire flag on key ``name`` for ``time`` milliseconds
+ with given ``option``. ``time`` can be represented by an
+ integer or a Python timedelta object.
+
+ Valid options are:
+ NX -> Set expiry only when the key has no expiry
+ XX -> Set expiry only when the key has an existing expiry
+ GT -> Set expiry only when the new expiry is greater than current one
+ LT -> Set expiry only when the new expiry is less than current one
For more information check https://redis.io/commands/pexpire
"""
if isinstance(time, datetime.timedelta):
time = int(time.total_seconds() * 1000)
- return self.execute_command("PEXPIRE", name, time)
+
+ exp_option = list()
+ if nx:
+ exp_option.append("NX")
+ if xx:
+ exp_option.append("XX")
+ if gt:
+ exp_option.append("GT")
+ if lt:
+ exp_option.append("LT")
+ return self.execute_command("PEXPIRE", name, time, *exp_option)
def pexpireat(self, name: KeyT, when: AbsExpiryT) -> ResponseT:
"""