diff options
author | dogukanteber <47397379+dogukanteber@users.noreply.github.com> | 2022-03-14 16:03:40 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 15:03:40 +0200 |
commit | fdf4f1adb9e2636a04343a3bfade2abac6877197 (patch) | |
tree | d74213480b25084a9ab4ec59daffd9d1a3e27355 /redis/commands/core.py | |
parent | f43c3e08ab0facf5a2d70bcd91365faf74d7e220 (diff) | |
download | redis-py-fdf4f1adb9e2636a04343a3bfade2abac6877197.tar.gz |
Add support for PEXPIREAT's options (#2027)
* Add support for PEXPIREAT's options
* add variables to the function header.
Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com>
Co-authored-by: dvora-h <dvora.heller@redis.com>
Diffstat (limited to 'redis/commands/core.py')
-rw-r--r-- | redis/commands/core.py | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/redis/commands/core.py b/redis/commands/core.py index 7e3514e..56d6fa9 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -1863,18 +1863,41 @@ class BasicKeyCommands(CommandsProtocol): exp_option.append("LT") return self.execute_command("PEXPIRE", name, time, *exp_option) - def pexpireat(self, name: KeyT, when: AbsExpiryT) -> ResponseT: + def pexpireat( + self, + name: KeyT, + when: AbsExpiryT, + nx: bool = False, + xx: bool = False, + gt: bool = False, + lt: bool = False, + ) -> ResponseT: """ - Set an expire flag on key ``name``. ``when`` can be represented - as an integer representing unix time in milliseconds (unix time * 1000) - or a Python datetime object. + Set an expire flag on key ``name`` with given ``option``. ``when`` + can be represented as an integer representing unix time in + milliseconds (unix time * 1000) or a Python datetime 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/pexpireat """ if isinstance(when, datetime.datetime): ms = int(when.microsecond / 1000) when = int(time.mktime(when.timetuple())) * 1000 + ms - return self.execute_command("PEXPIREAT", name, when) + 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("PEXPIREAT", name, when, *exp_option) def pexpiretime(self, key: str) -> int: """ |