diff options
author | dogukanteber <47397379+dogukanteber@users.noreply.github.com> | 2022-03-14 16:03:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 15:03:06 +0200 |
commit | eac3a34d162aa83c3094cbab80d535ca92fdf972 (patch) | |
tree | 717a39d921220fb4ae97b111964064829fe68903 /redis/commands/core.py | |
parent | 2c405855021ccc8d4a45fa1aae352ddb303baae0 (diff) | |
download | redis-py-eac3a34d162aa83c3094cbab80d535ca92fdf972.tar.gz |
Add support for EXPIREAT command's options (#2024)
* Add support for EXPIREAT command's options
* Fix linter errors
* Make changes on method arguments
* Fix linter errors
* add variables to the function header
Co-authored-by: Chayim <chayim@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 | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/redis/commands/core.py b/redis/commands/core.py index 108da1b..5b6d42b 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -1538,16 +1538,42 @@ class BasicKeyCommands(CommandsProtocol): return self.execute_command("EXPIRE", name, time, *exp_option) - def expireat(self, name: KeyT, when: AbsExpiryT) -> ResponseT: + def expireat( + 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 indicating unix time or a Python datetime object. + Set an expire flag on key ``name`` with given ``option``. ``when`` + can be represented as an integer indicating unix time 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/expireat """ if isinstance(when, datetime.datetime): when = int(time.mktime(when.timetuple())) - return self.execute_command("EXPIREAT", 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("EXPIREAT", name, when, *exp_option) def expiretime(self, key: str) -> int: """ |