Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Redis 6.2] Add EXAT/PXAT options to SET #1028

Merged
merged 1 commit into from Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/redis.rb
Expand Up @@ -834,14 +834,18 @@ def incrbyfloat(key, increment)
# @param [Hash] options
# - `:ex => Integer`: Set the specified expire time, in seconds.
# - `:px => Integer`: Set the specified expire time, in milliseconds.
# - `:exat => Integer` : Set the specified Unix time at which the key will expire, in seconds.
# - `:pxat => Integer` : Set the specified Unix time at which the key will expire, in milliseconds.
# - `:nx => true`: Only set the key if it does not already exist.
# - `:xx => true`: Only set the key if it already exist.
# - `:keepttl => true`: Retain the time to live associated with the key.
# @return [String, Boolean] `"OK"` or true, false if `:nx => true` or `:xx => true`
def set(key, value, ex: nil, px: nil, nx: nil, xx: nil, keepttl: nil)
def set(key, value, ex: nil, px: nil, exat: nil, pxat: nil, nx: nil, xx: nil, keepttl: nil)
args = [:set, key, value.to_s]
args << "EX" << ex if ex
args << "PX" << px if px
args << "EXAT" << exat if exat
args << "PXAT" << pxat if pxat
args << "NX" if nx
args << "XX" if xx
args << "KEEPTTL" if keepttl
Expand Down
14 changes: 14 additions & 0 deletions test/lint/strings.rb
Expand Up @@ -51,6 +51,20 @@ def test_set_with_px
end
end

def test_set_with_exat
target_version "6.2" do
r.set("foo", "bar", exat: Time.now.to_i + 2)
assert_in_range 0..2, r.ttl("foo")
end
end

def test_set_with_pxat
target_version "6.2" do
r.set("foo", "bar", pxat: (1000 * Time.now.to_i) + 2000)
assert_in_range 0..2, r.ttl("foo")
end
end

def test_set_with_nx
target_version "2.6.12" do
r.set("foo", "qux", nx: true)
Expand Down