File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -376,6 +376,25 @@ def client_getname(self):
376376 "Returns the current connection name"
377377 return self .execute_command ('CLIENT GETNAME' )
378378
379+ def client_reply (self , reply ):
380+ """Enable and disable redis server replies.
381+ ``reply`` Must be ON OFF or SKIP,
382+ ON - The default most with server replies to commands
383+ OFF - Disable server responses to commands
384+ SKIP - Skip the response of the immediately following command.
385+
386+ Note: When setting OFF or SKIP replies, you will need a client object
387+ with a timeout specified in seconds, and will need to catch the
388+ TimeoutError.
389+ The test_client_reply unit test illustrates this, and
390+ conftest.py has a client with a timeout.
391+ See https://redis.io/commands/client-reply
392+ """
393+ replies = ['ON' , 'OFF' , 'SKIP' ]
394+ if reply not in replies :
395+ raise DataError ('CLIENT REPLY must be one of %r' % replies )
396+ return self .execute_command ("CLIENT REPLY" , reply )
397+
379398 def client_id (self ):
380399 "Returns the current connection id"
381400 return self .execute_command ('CLIENT ID' )
Original file line number Diff line number Diff line change @@ -100,6 +100,12 @@ def r(request):
100100 yield client
101101
102102
103+ @pytest .fixture ()
104+ def r_timeout (request ):
105+ with _get_client (redis .Redis , request , socket_timeout = 1 ) as client :
106+ yield client
107+
108+
103109@pytest .fixture ()
104110def r2 (request ):
105111 "A second client for tests that need multiple"
Original file line number Diff line number Diff line change @@ -478,6 +478,19 @@ def test_client_pause(self, r):
478478 def test_client_unpause (self , r ):
479479 assert r .client_unpause () == b'OK'
480480
481+ @skip_if_server_version_lt ('3.2.0' )
482+ def test_client_reply (self , r , r_timeout ):
483+ assert r_timeout .client_reply ('ON' ) == b'OK'
484+ with pytest .raises (exceptions .TimeoutError ):
485+ r_timeout .client_reply ('OFF' )
486+
487+ r_timeout .client_reply ('SKIP' )
488+
489+ assert r_timeout .set ('foo' , 'bar' )
490+
491+ # validate it was set
492+ assert r .get ('foo' ) == b'bar'
493+
481494 def test_config_get (self , r ):
482495 data = r .config_get ()
483496 assert 'maxmemory' in data
You can’t perform that action at this time.
0 commit comments