From 1e52c1145954a0ed8554a8f8788b3c726e4f8d72 Mon Sep 17 00:00:00 2001 From: Julien Chien Date: Tue, 30 Jan 2024 13:13:07 -0800 Subject: [PATCH] Add PEXPIRETIME edit expiretime's descriptions --- lib/redis/commands/keys.rb | 12 ++++++++++-- lib/redis/distributed.rb | 5 +++++ test/lint/value_types.rb | 13 +++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/redis/commands/keys.rb b/lib/redis/commands/keys.rb index 0b731c885..f507a924f 100644 --- a/lib/redis/commands/keys.rb +++ b/lib/redis/commands/keys.rb @@ -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 @@ -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 diff --git a/lib/redis/distributed.rb b/lib/redis/distributed.rb index 21062c12b..33185d7c3 100644 --- a/lib/redis/distributed.rb +++ b/lib/redis/distributed.rb @@ -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) diff --git a/test/lint/value_types.rb b/test/lint/value_types.rb index 6edff9725..f8fce5b44 100644 --- a/test/lint/value_types.rb +++ b/test/lint/value_types.rb @@ -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)