Skip to content

Commit 8ad2c39

Browse files
committed
add expiretime
1 parent 15f315a commit 8ad2c39

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

redis/commands/core.py

+9
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,15 @@ def expireat(self, name, when):
12331233
when = int(time.mktime(when.timetuple()))
12341234
return self.execute_command("EXPIREAT", name, when)
12351235

1236+
def expiretime(self, key: str) -> int:
1237+
"""
1238+
Returns the absolute Unix timestamp (since January 1, 1970) in seconds
1239+
at which the given key will expire.
1240+
1241+
For more information check https://redis.io/commands/expiretime
1242+
"""
1243+
return self.execute_command("EXPIRETIME", key)
1244+
12361245
def get(self, name):
12371246
"""
12381247
Return the value at key ``name``, or None if the key doesn't exist

tests/test_commands.py

+6
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,12 @@ def test_expireat_unixtime(self, r):
10141014
assert r.expireat("a", expire_at_seconds) is True
10151015
assert 0 < r.ttl("a") <= 61
10161016

1017+
# @skip_if_server_version_lt("7.0.0") turn on after redis 7 release
1018+
def test_expiretime(self, unstable_r):
1019+
unstable_r.set("a", "foo")
1020+
unstable_r.expireat("a", 33177117420)
1021+
assert unstable_r.expiretime("a") == 33177117420
1022+
10171023
def test_get_and_set(self, r):
10181024
# get and set can't be tested independently of each other
10191025
assert r.get("a") is None

0 commit comments

Comments
 (0)