Skip to content

Commit 2e693be

Browse files
committed
Add Expiretime
make rubocop happy is my only desire
1 parent e16cab8 commit 2e693be

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/redis/commands/keys.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ 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
109+
#
110+
# @param [String] key
111+
# @return [Integer] expiry time of the key, specified as a UNIX timestamp
112+
def expiretime(key)
113+
send_command([:expiretime, key])
114+
end
115+
108116
# Get the time to live (in seconds) for a key.
109117
#
110118
# @param [String] key

lib/redis/distributed.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ def expireat(key, unix_time, **kwargs)
130130
node_for(key).expireat(key, unix_time, **kwargs)
131131
end
132132

133+
# Get the expiration for a key as a UNIX timestamp.
134+
def expiretime(key)
135+
node_for(key).expiretime(key)
136+
end
137+
133138
# Get the time to live (in seconds) for a key.
134139
def ttl(key)
135140
node_for(key).ttl(key)

test/lint/value_types.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ def test_expireat_keywords
118118
end
119119
end
120120

121+
def test_expiretime
122+
target_version "7.0.0" do
123+
r.set("foo", "blar")
124+
assert_equal(-1, r.expiretime("foo"))
125+
126+
exp_time = (Time.now + 2).to_i
127+
r.expireat("foo", exp_time)
128+
assert_equal exp_time, r.expiretime("foo")
129+
130+
assert_equal(-2, r.expiretime("key-that-exists-not"))
131+
end
132+
end
133+
121134
def test_pexpireat
122135
r.set("foo", "s1")
123136
assert r.pexpireat("foo", (Time.now + 2).to_i * 1_000)

0 commit comments

Comments
 (0)