11from __future__ import unicode_literals
22from redis ._compat import unicode
3- from .conftest import skip_if_server_version_lt
3+ from .conftest import wait_for_command
44
55
6- def wait_for_command (client , monitor , command ):
7- # issue a command with a key name that's local to this process.
8- # if we find a command with our key before the command we're waiting
9- # for, something went wrong
10- key = '__REDIS-PY-%s__' % str (client .client_id ())
11- client .get (key )
12- while True :
13- monitor_response = monitor .next_command ()
14- if command in monitor_response ['command' ]:
15- return monitor_response
16- if key in monitor_response ['command' ]:
17- return None
18-
19-
20- class TestPipeline (object ):
21- @skip_if_server_version_lt ('5.0.0' )
6+ class TestMonitor (object ):
227 def test_wait_command_not_found (self , r ):
238 "Make sure the wait_for_command func works when command is not found"
249 with r .monitor () as m :
2510 response = wait_for_command (r , m , 'nothing' )
2611 assert response is None
2712
28- @skip_if_server_version_lt ('5.0.0' )
2913 def test_response_values (self , r ):
3014 with r .monitor () as m :
3115 r .ping ()
@@ -37,22 +21,19 @@ def test_response_values(self, r):
3721 assert isinstance (response ['client_port' ], unicode )
3822 assert response ['command' ] == 'PING'
3923
40- @skip_if_server_version_lt ('5.0.0' )
4124 def test_command_with_quoted_key (self , r ):
4225 with r .monitor () as m :
4326 r .get ('foo"bar' )
4427 response = wait_for_command (r , m , 'GET foo"bar' )
4528 assert response ['command' ] == 'GET foo"bar'
4629
47- @skip_if_server_version_lt ('5.0.0' )
4830 def test_command_with_binary_data (self , r ):
4931 with r .monitor () as m :
5032 byte_string = b'foo\x92 '
5133 r .get (byte_string )
5234 response = wait_for_command (r , m , 'GET foo\\ x92' )
5335 assert response ['command' ] == 'GET foo\\ x92'
5436
55- @skip_if_server_version_lt ('5.0.0' )
5637 def test_lua_script (self , r ):
5738 with r .monitor () as m :
5839 script = 'return redis.call("GET", "foo")'
0 commit comments