Skip to content

Commit 3662a56

Browse files
committed
Add httl and integrate in hexpire test
Context: redis#1324 (comment) `httl` documentation: https://redis.io/docs/latest/commands/httl/
1 parent 0744aec commit 3662a56

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/redis/commands/hashes.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,20 @@ def hscan_each(key, **options, &block)
267267
def hexpire(key, ttl, *fields)
268268
send_command([:hexpire, key, ttl, 'FIELDS', fields.length, *fields])
269269
end
270+
271+
# Returns the time to live in seconds for one or more fields.
272+
#
273+
# @example
274+
# redis.hset("hash", "f1", "v1", "f2", "v2")
275+
# redis.hexpire("hash", 10, "f1") # => [1]
276+
# redis.httl("hash", "f1", "f2", "f3") # => [10, -1, -2]
277+
#
278+
# @param [String] key
279+
# @param [Array<String>] fields
280+
# @return [Array<Integer>] The number of fields that were added to the hash
281+
def httl(key, *fields)
282+
send_command([:httl, key, 'FIELDS', fields.length, *fields])
283+
end
270284
end
271285
end
272286
end

test/lint/hashes.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,8 @@ def test_hexpire
232232
target_version "7.4.0" do
233233
r.hset("foo", "f1", "v2")
234234

235-
assert_equal [1], r.hexpire("foo", 1, "f1")
236-
assert r.hexists("foo", "f1")
237-
238-
sleep(1)
239-
240-
refute r.hexists("foo", "f1")
235+
assert_equal [1], r.hexpire("foo", 4, "f1")
236+
assert_in_range(1..4, r.httl("foo", "f1")[0])
241237
end
242238
end
243239
end

0 commit comments

Comments
 (0)