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 PEXPIRETIME #1251

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 10 additions & 2 deletions lib/redis/commands/keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ def expireat(key, unix_time, nx: nil, xx: nil, gt: nil, lt: nil)
send_command(args, &Boolify)
end

# Get a key's expiration time as an absolute Unix timestamp (since January 1, 1970) in seconds
# Get a key's expiry time specified as number of seconds from UNIX Epoch
#
# @param [String] key
# @return [Integer] expiry time of the key, specified as a UNIX timestamp
# @return [Integer] expiry time specified as number of seconds from UNIX Epoch
def expiretime(key)
send_command([:expiretime, key])
end
Expand Down Expand Up @@ -169,6 +169,14 @@ def pexpireat(key, ms_unix_time, nx: nil, xx: nil, gt: nil, lt: nil)
send_command(args, &Boolify)
end

# Get a key's expiry time specified as number of milliseconds from UNIX Epoch
#
# @param [String] key
# @return [Integer] expiry time specified as number of milliseconds from UNIX Epoch
def pexpiretime(key)
send_command([:pexpiretime, key])
end

# Get the time to live (in milliseconds) for a key.
#
# @param [String] key
Expand Down
5 changes: 5 additions & 0 deletions lib/redis/distributed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ def pexpireat(key, ms_unix_time, **kwarg)
node_for(key).pexpireat(key, ms_unix_time, **kwarg)
end

# Get the expiration for a key as number of milliseconds from UNIX Epoch.
def pexpiretime(key)
node_for(key).pexpiretime(key)
end

# Get the time to live (in milliseconds) for a key.
def pttl(key)
node_for(key).pttl(key)
Expand Down
13 changes: 13 additions & 0 deletions test/lint/value_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ def test_pexpireat_keywords
end
end

def test_pexpiretime
target_version "7.0.0" do
r.set("foo", "blar")
assert_equal(-1, r.pexpiretime("foo"))

exp_time = (Time.now + 2).to_i * 1_000
r.pexpireat("foo", exp_time)
assert_equal exp_time, r.pexpiretime("foo")

assert_equal(-2, r.pexpiretime("key-that-exists-not"))
end
end

def test_persist
r.set("foo", "s1")
r.expire("foo", 1)
Expand Down