Skip to content

Commit 72edad4

Browse files
author
Nicolas Pepin-Perreault
committed
to keep backwards compatibility, assume no REPLACE modifier by default
1 parent 7658d86 commit 72edad4

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

lib/redis.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,11 @@ def dump(key)
460460
# @param [String] serialized_value
461461
# @param [Hash] options
462462
# - `:replace => Boolean`: if false, raises an error if key already exists
463-
# @param [Hash] replace
464463
# @raise [Redis::CommandError]
465464
# @return [String] `"OK"`
466465
def restore(key, ttl, serialized_value, options = {})
467466
args = [:restore, key, ttl, serialized_value]
468-
args << 'REPLACE' if options.fetch(:replace, true)
467+
args << 'REPLACE' if options[:replace]
469468

470469
synchronize do |client|
471470
client.call(args)

lib/redis/distributed.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ def dump(key)
145145

146146
# Create a key using the serialized value, previously obtained using DUMP.
147147
def restore(key, ttl, serialized_value, options = {})
148-
options[:replace] = true unless options.key?(:replace)
149148
node_for(key).restore(key, ttl, serialized_value, options)
150149
end
151150

test/lint/value_types.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ def test_dump_and_restore
9595
assert [0, 1].include? r.ttl("bar")
9696

9797
r.set("bar", "somethingelse")
98+
assert_raises(Redis::CommandError) { r.restore("bar", 1000, w) } # ensure by default replace is false
9899
assert_raises(Redis::CommandError) { r.restore("bar", 1000, w, :replace => false) }
99100
assert_equal "somethingelse", r.get("bar")
101+
assert r.restore("bar", 1000, w, :replace => true)
102+
assert_equal ["b", "c", "d"], r.lrange("bar", 0, -1)
103+
assert [0, 1].include? r.ttl("bar")
100104
end
101105
end
102106

0 commit comments

Comments
 (0)