Skip to content

Commit 6338454

Browse files
committed
Refactor _scan so that it doesn't need to check for its caller.
1 parent 0c362af commit 6338454

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

lib/redis.rb

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,22 +2239,18 @@ def evalsha(*args)
22392239
_eval(:evalsha, args)
22402240
end
22412241

2242-
def _scan(command, cursor, options = {}, &block)
2243-
# SSCAN/ZSCAN/HSCAN need a key to work on
2244-
args = []
2245-
2246-
if command != :scan
2247-
key = options[:key]
2248-
args.concat([key]) if key
2249-
end
2242+
def _scan(command, cursor, args, options = {}, &block)
2243+
# SSCAN/ZSCAN/HSCAN already prepend the key to +args+.
22502244

2251-
args.concat([cursor])
2245+
args << cursor
22522246

2253-
match = options[:match]
2254-
args.concat(["MATCH", match]) if match
2247+
if match = options[:match]
2248+
args.concat(["MATCH", match])
2249+
end
22552250

2256-
count = options[:count]
2257-
args.concat(["COUNT", count]) if count
2251+
if count = options[:count]
2252+
args.concat(["COUNT", count])
2253+
end
22582254

22592255
synchronize do |client|
22602256
client.call([command] + args, &block)
@@ -2277,7 +2273,7 @@ def _scan(command, cursor, options = {}, &block)
22772273
#
22782274
# @return [String, Array<String>] the next cursor and all found keys
22792275
def scan(cursor, options={})
2280-
_scan(:scan, cursor, options)
2276+
_scan(:scan, cursor, [], options)
22812277
end
22822278

22832279
# Scan a hash
@@ -2292,7 +2288,7 @@ def scan(cursor, options={})
22922288
#
22932289
# @return [String, Array<[String, String]>] the next cursor and all found keys
22942290
def hscan(key, cursor, options={})
2295-
_scan(:hscan, cursor, options.merge(:key => key)) do |reply|
2291+
_scan(:hscan, cursor, [key], options) do |reply|
22962292
[reply[0], _pairify(reply[1])]
22972293
end
22982294
end
@@ -2310,7 +2306,7 @@ def hscan(key, cursor, options={})
23102306
# @return [String, Array<[String, Float]>] the next cursor and all found
23112307
# members and scores
23122308
def zscan(key, cursor, options={})
2313-
_scan(:zscan, cursor, options.merge(:key => key)) do |reply|
2309+
_scan(:zscan, cursor, [key], options) do |reply|
23142310
[reply[0], _floatify_pairs.call(reply[1])]
23152311
end
23162312
end
@@ -2327,7 +2323,7 @@ def zscan(key, cursor, options={})
23272323
#
23282324
# @return [String, Array<String>] the next cursor and all found members
23292325
def sscan(key, cursor, options={})
2330-
_scan(:sscan, cursor, options.merge(:key => key))
2326+
_scan(:sscan, cursor, [key], options)
23312327
end
23322328

23332329
def id

0 commit comments

Comments
 (0)