Skip to content

Commit f987a0c

Browse files
authored
Add support for EXPIRETIME (#1860)
* add expiretime * skip test
1 parent 4dc48d6 commit f987a0c

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
@@ -1523,6 +1523,15 @@ def expireat(self, name: KeyT, when: AbsExpiryT) -> ResponseT:
15231523
when = int(time.mktime(when.timetuple()))
15241524
return self.execute_command("EXPIREAT", name, when)
15251525

1526+
def expiretime(self, key: str) -> int:
1527+
"""
1528+
Returns the absolute Unix timestamp (since January 1, 1970) in seconds
1529+
at which the given key will expire.
1530+
1531+
For more information check https://redis.io/commands/expiretime
1532+
"""
1533+
return self.execute_command("EXPIRETIME", key)
1534+
15261535
def get(self, name: KeyT) -> ResponseT:
15271536
"""
15281537
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
@@ -1075,6 +1075,12 @@ def test_expireat_unixtime(self, r):
10751075
assert r.expireat("a", expire_at_seconds) is True
10761076
assert 0 < r.ttl("a") <= 61
10771077

1078+
@skip_if_server_version_lt("7.0.0")
1079+
def test_expiretime(self, r):
1080+
r.set("a", "foo")
1081+
r.expireat("a", 33177117420)
1082+
assert r.expiretime("a") == 33177117420
1083+
10781084
def test_get_and_set(self, r):
10791085
# get and set can't be tested independently of each other
10801086
assert r.get("a") is None

0 commit comments

Comments
 (0)