Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PEXPIRETIME #1861

Merged
merged 3 commits into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,15 @@ def pexpireat(self, name, when):
when = int(time.mktime(when.timetuple())) * 1000 + ms
return self.execute_command("PEXPIREAT", name, when)

def pexpiretime(self, key: str) -> int:
"""
Returns the absolute Unix timestamp (since January 1, 1970) in milliseconds
at which the given key will expire.

For more information check https://redis.io/commands/pexpiretime
"""
return self.execute_command("PEXPIRETIME", key)

def psetex(self, name, time_ms, value):
"""
Set the value of key ``name`` to ``value`` that expires in ``time_ms``
Expand Down
6 changes: 6 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,12 @@ def test_pexpireat_unixtime(self, r):
assert r.pexpireat("a", expire_at_seconds) is True
assert 0 < r.pttl("a") <= 61000

# @skip_if_server_version_lt("7.0.0") turn on after redis 7 release
def test_pexpiretime(self, unstable_r):
unstable_r.set("a", "foo")
unstable_r.pexpireat("a", 33177117420000)
assert unstable_r.pexpiretime("a") == 33177117420000

@skip_if_server_version_lt("2.6.0")
def test_psetex(self, r):
assert r.psetex("a", 1000, "value")
Expand Down