Skip to content

Commit cd88550

Browse files
authored
Merge pull request #1251 from wholien/jc/add-pexpiretime
Add PEXPIRETIME
2 parents a51d50c + 1e52c11 commit cd88550

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

lib/redis/commands/keys.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ def expireat(key, unix_time, nx: nil, xx: nil, gt: nil, lt: nil)
105105
send_command(args, &Boolify)
106106
end
107107

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

172+
# Get a key's expiry time specified as number of milliseconds from UNIX Epoch
173+
#
174+
# @param [String] key
175+
# @return [Integer] expiry time specified as number of milliseconds from UNIX Epoch
176+
def pexpiretime(key)
177+
send_command([:pexpiretime, key])
178+
end
179+
172180
# Get the time to live (in milliseconds) for a key.
173181
#
174182
# @param [String] key

lib/redis/distributed.rb

+5
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ def pexpireat(key, ms_unix_time, **kwarg)
150150
node_for(key).pexpireat(key, ms_unix_time, **kwarg)
151151
end
152152

153+
# Get the expiration for a key as number of milliseconds from UNIX Epoch.
154+
def pexpiretime(key)
155+
node_for(key).pexpiretime(key)
156+
end
157+
153158
# Get the time to live (in milliseconds) for a key.
154159
def pttl(key)
155160
node_for(key).pttl(key)

test/lint/value_types.rb

+13
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ def test_pexpireat_keywords
153153
end
154154
end
155155

156+
def test_pexpiretime
157+
target_version "7.0.0" do
158+
r.set("foo", "blar")
159+
assert_equal(-1, r.pexpiretime("foo"))
160+
161+
exp_time = (Time.now + 2).to_i * 1_000
162+
r.pexpireat("foo", exp_time)
163+
assert_equal exp_time, r.pexpiretime("foo")
164+
165+
assert_equal(-2, r.pexpiretime("key-that-exists-not"))
166+
end
167+
end
168+
156169
def test_persist
157170
r.set("foo", "s1")
158171
r.expire("foo", 1)

0 commit comments

Comments
 (0)