Skip to content

Commit c97360b

Browse files
authored
Merge pull request #1028 from magni-/pp/set-exat
[Redis 6.2] Add EXAT/PXAT options to SET
2 parents 688ac95 + aec0ba7 commit c97360b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/redis.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,14 +834,18 @@ def incrbyfloat(key, increment)
834834
# @param [Hash] options
835835
# - `:ex => Integer`: Set the specified expire time, in seconds.
836836
# - `:px => Integer`: Set the specified expire time, in milliseconds.
837+
# - `:exat => Integer` : Set the specified Unix time at which the key will expire, in seconds.
838+
# - `:pxat => Integer` : Set the specified Unix time at which the key will expire, in milliseconds.
837839
# - `:nx => true`: Only set the key if it does not already exist.
838840
# - `:xx => true`: Only set the key if it already exist.
839841
# - `:keepttl => true`: Retain the time to live associated with the key.
840842
# @return [String, Boolean] `"OK"` or true, false if `:nx => true` or `:xx => true`
841-
def set(key, value, ex: nil, px: nil, nx: nil, xx: nil, keepttl: nil)
843+
def set(key, value, ex: nil, px: nil, exat: nil, pxat: nil, nx: nil, xx: nil, keepttl: nil)
842844
args = [:set, key, value.to_s]
843845
args << "EX" << ex if ex
844846
args << "PX" << px if px
847+
args << "EXAT" << exat if exat
848+
args << "PXAT" << pxat if pxat
845849
args << "NX" if nx
846850
args << "XX" if xx
847851
args << "KEEPTTL" if keepttl

test/lint/strings.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ def test_set_with_px
5151
end
5252
end
5353

54+
def test_set_with_exat
55+
target_version "6.2" do
56+
r.set("foo", "bar", exat: Time.now.to_i + 2)
57+
assert_in_range 0..2, r.ttl("foo")
58+
end
59+
end
60+
61+
def test_set_with_pxat
62+
target_version "6.2" do
63+
r.set("foo", "bar", pxat: (1000 * Time.now.to_i) + 2000)
64+
assert_in_range 0..2, r.ttl("foo")
65+
end
66+
end
67+
5468
def test_set_with_nx
5569
target_version "2.6.12" do
5670
r.set("foo", "qux", nx: true)

0 commit comments

Comments
 (0)