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 EXPIRETIME #1860

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 @@ -1233,6 +1233,15 @@ def expireat(self, name, when):
when = int(time.mktime(when.timetuple()))
return self.execute_command("EXPIREAT", name, when)

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

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

def get(self, name):
"""
Return the value at key ``name``, or None if the key doesn't exist
Expand Down
6 changes: 6 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,12 @@ def test_expireat_unixtime(self, r):
assert r.expireat("a", expire_at_seconds) is True
assert 0 < r.ttl("a") <= 61

# @skip_if_server_version_lt("7.0.0") turn on after redis 7 release
def test_expiretime(self, unstable_r):
unstable_r.set("a", "foo")
unstable_r.expireat("a", 33177117420)
assert unstable_r.expiretime("a") == 33177117420

def test_get_and_set(self, r):
# get and set can't be tested independently of each other
assert r.get("a") is None
Expand Down