Skip to content

Commit 99bbe17

Browse files
committed
Passing the timeout as a positional argument is deprecated, it should be passed as a keyword argument
1 parent 5d9a751 commit 99bbe17

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

lib/redis/connection/memory.rb

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -781,28 +781,28 @@ def persist(key)
781781
def hset(key, *fields)
782782
fields = fields.first if fields.size == 1 && fields.first.is_a?(Hash)
783783
raise_argument_error('hset') if fields.empty?
784-
784+
785785
is_list_of_arrays = fields.all?{|field| field.instance_of?(Array)}
786-
786+
787787
raise_argument_error('hmset') if fields.size.odd? and !is_list_of_arrays
788788
raise_argument_error('hmset') if is_list_of_arrays and !fields.all?{|field| field.length == 2}
789-
789+
790790
data_type_check(key, Hash)
791791
insert_count = 0
792792
data[key] ||= {}
793-
793+
794794
if fields.is_a?(Hash)
795795
insert_count = fields.keys.size - (data[key].keys & fields.keys).size
796-
796+
797797
data[key].merge!(fields)
798798
else
799799
fields.each_slice(2) do |field|
800800
insert_count += 1 if data[key][field[0].to_s].nil?
801-
801+
802802
data[key][field[0].to_s] = field[1].to_s
803803
end
804804
end
805-
805+
806806
insert_count
807807
end
808808

@@ -1156,12 +1156,12 @@ def zpopmin(key, count = nil)
11561156
count.nil? ? results.first : results.flatten
11571157
end
11581158

1159-
def bzpopmax(*args)
1160-
bzpop(:bzpopmax, args)
1159+
def bzpopmax(*args, timeout: 0)
1160+
bzpop(:bzpopmax, args, timeout)
11611161
end
11621162

1163-
def bzpopmin(*args)
1164-
bzpop(:bzpopmin, args)
1163+
def bzpopmin(*args, timeout: 0)
1164+
bzpop(:bzpopmin, args, timeout)
11651165
end
11661166

11671167
def zcard(key)
@@ -1600,15 +1600,7 @@ def srandmember_multiple(key, number)
16001600
end
16011601
end
16021602

1603-
def bzpop(command, args)
1604-
timeout =
1605-
if args.last.is_a?(Hash)
1606-
args.pop[:timeout]
1607-
elsif args.last.respond_to?(:to_int)
1608-
args.pop.to_int
1609-
end
1610-
1611-
timeout ||= 0
1603+
def bzpop(command, args, timeout)
16121604
single_pop_command = command.to_s[1..-1]
16131605
keys = args.flatten
16141606
keys.each do |key|

spec/sorted_sets_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ module FakeRedis
120120
it "should pop members with the highest score from first sorted set that is non-empty" do
121121
@client.zadd("key1", [1, "val1", 2, "val2"])
122122
@client.zadd("key2", [3, "val3"])
123-
expect(@client.bzpopmax("nonexistent", "key1", "key2", 0)).to eq(["key1", "val2", 2.0])
123+
expect(@client.bzpopmax("nonexistent", "key1", "key2", timeout: 0)).to eq(["key1", "val2", 2.0])
124124
expect(@client.bzpopmax("nonexistent")).to eq(nil)
125125
end
126126

127127
it "should pop members with the lowest score from first sorted set that is non-empty" do
128128
@client.zadd("key1", [1, "val1", 2, "val2"])
129129
@client.zadd("key2", [3, "val3"])
130-
expect(@client.bzpopmin("nonexistent", "key1", "key2", 0)).to eq(["key1", "val1", 1.0])
130+
expect(@client.bzpopmin("nonexistent", "key1", "key2", timeout: 0)).to eq(["key1", "val1", 1.0])
131131
expect(@client.bzpopmin("nonexistent")).to eq(nil)
132132
end
133133

0 commit comments

Comments
 (0)