Skip to content

Commit 1faca3c

Browse files
authored
fix: more compatibility with redis client (#86)
1 parent 0d7da29 commit 1faca3c

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lib/redis_client/cluster.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ def inspect
1717
"#<#{self.class.name} #{@router.node.node_keys.join(', ')}>"
1818
end
1919

20-
def call(*command, **kwargs)
21-
@router.send_command(:call, *command, **kwargs)
20+
def call(*command, **kwargs, &block)
21+
@router.send_command(:call, *command, **kwargs, &block)
2222
end
2323

24-
def call_once(*command, **kwargs)
25-
@router.send_command(:call_once, *command, **kwargs)
24+
def call_once(*command, **kwargs, &block)
25+
@router.send_command(:call_once, *command, **kwargs, &block)
2626
end
2727

28-
def blocking_call(timeout, *command, **kwargs)
29-
@router.send_command(:blocking_call, timeout, *command, **kwargs)
28+
def blocking_call(timeout, *command, **kwargs, &block)
29+
@router.send_command(:blocking_call, timeout, *command, **kwargs, &block)
3030
end
3131

3232
def scan(*args, **kwargs, &block)
@@ -74,10 +74,10 @@ def close
7474

7575
private
7676

77-
def method_missing(name, *args, **kwargs)
77+
def method_missing(name, *args, **kwargs, &block)
7878
if @router.command_exists?(name)
7979
args.unshift(name)
80-
return @router.send_command(:call, *args)
80+
return @router.send_command(:call, *args, **kwargs, &block)
8181
end
8282

8383
super

test/redis_client/test_cluster.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,32 @@ def test_inspect
2323

2424
def test_call
2525
assert_raises(ArgumentError) { @client.call }
26+
2627
(0..9).each do |i|
2728
assert_equal('OK', @client.call('SET', "key#{i}", i), "Case: SET: key#{i}")
2829
wait_for_replication
2930
assert_equal(i.to_s, @client.call('GET', "key#{i}"), "Case: GET: key#{i}")
3031
end
32+
33+
assert(@client.call('PING') { |r| r == 'PONG' })
34+
35+
assert_equal(2, @client.call('HSET', 'hash', { foo: 1, bar: 2 }))
36+
assert_equal(%w[1 2], @client.call('HMGET', 'hash', %w[foo bar]))
3137
end
3238

3339
def test_call_once
3440
assert_raises(ArgumentError) { @client.call_once }
41+
3542
(0..9).each do |i|
3643
assert_equal('OK', @client.call_once('SET', "key#{i}", i), "Case: SET: key#{i}")
3744
wait_for_replication
3845
assert_equal(i.to_s, @client.call_once('GET', "key#{i}"), "Case: GET: key#{i}")
3946
end
47+
48+
assert(@client.call_once('PING') { |r| r == 'PONG' })
49+
50+
assert_equal(2, @client.call_once('HSET', 'hash', { foo: 1, bar: 2 }))
51+
assert_equal(%w[1 2], @client.call_once('HMGET', 'hash', %w[foo bar]))
4052
end
4153

4254
def test_blocking_call

0 commit comments

Comments
 (0)