File tree 3 files changed +37
-0
lines changed
3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -376,6 +376,24 @@ def client_getname(self):
376
376
"Returns the current connection name"
377
377
return self .execute_command ('CLIENT GETNAME' )
378
378
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 with a
387
+ timeout specified in seconds, and will need to catch the TimeoutError.
388
+ The test_client_reply unit test illustrates this, and conftest.py has a
389
+ client with a timeout.
390
+ See https://redis.io/commands/client-reply
391
+ """
392
+ replies = ['ON' , 'OFF' , 'SKIP' ]
393
+ if reply not in replies :
394
+ raise DataError ('CLIENT REPLY must be one of %r' % replies )
395
+ return self .execute_command ("CLIENT REPLY" , reply )
396
+
379
397
def client_id (self ):
380
398
"Returns the current connection id"
381
399
return self .execute_command ('CLIENT ID' )
Original file line number Diff line number Diff line change @@ -100,6 +100,12 @@ def r(request):
100
100
yield client
101
101
102
102
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
+
103
109
@pytest .fixture ()
104
110
def r2 (request ):
105
111
"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):
478
478
def test_client_unpause (self , r ):
479
479
assert r .client_unpause () == b'OK'
480
480
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
+
481
494
def test_config_get (self , r ):
482
495
data = r .config_get ()
483
496
assert 'maxmemory' in data
You can’t perform that action at this time.
0 commit comments