Skip to content

Commit ba82682

Browse files
authored
Merge pull request #913 from Marketcircle/v6-set
Support KEEPTTL option in SET command
2 parents cc4d1e0 + f59a49f commit ba82682

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Increase buffer size in the ruby connector. See #880.
1010
* Fix thread safety of `Redis.queue`. See #878.
1111
* Deprecate `Redis::Future#==` as it's likely to be a mistake. See #876.
12+
* Support `KEEPTTL` option for SET command. See #913.
1213

1314
# 4.1.3
1415

lib/redis.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ def incrbyfloat(key, increment)
786786
# - `:px => Integer`: Set the specified expire time, in milliseconds.
787787
# - `:nx => true`: Only set the key if it does not already exist.
788788
# - `:xx => true`: Only set the key if it already exist.
789+
# - `:keepttl => true`: Retain the time to live associated with the key.
789790
# @return [String, Boolean] `"OK"` or true, false if `:nx => true` or `:xx => true`
790791
def set(key, value, options = {})
791792
args = []
@@ -802,6 +803,9 @@ def set(key, value, options = {})
802803
xx = options[:xx]
803804
args.concat(["XX"]) if xx
804805

806+
keepttl = options[:keepttl]
807+
args.concat(["KEEPTTL"]) if keepttl
808+
805809
synchronize do |client|
806810
if nx || xx
807811
client.call([:set, key, value.to_s] + args, &BoolifySet)

test/lint/strings.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ def test_set_with_xx
7474
end
7575
end
7676

77+
def test_set_with_keepttl
78+
target_version "6.0.0" do
79+
r.set("foo", "qux", :ex => 2)
80+
assert_in_range 0..2, r.ttl("foo")
81+
r.set("foo", "bar", :keepttl => true)
82+
assert_in_range 0..2, r.ttl("foo")
83+
end
84+
end
85+
7786
def test_setex
7887
assert r.setex("foo", 1, "bar")
7988
assert_equal "bar", r.get("foo")

0 commit comments

Comments
 (0)