summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayim <chayim@users.noreply.github.com>2021-09-30 13:35:10 +0300
committerGitHub <noreply@github.com>2021-09-30 13:35:10 +0300
commit6c70fcdd10cca7de15175a77824009babfac4417 (patch)
treea2143f99e26d2304cd433f9f358f0128ef4e1bc7
parentbfc4cd92c8070de9bfa7736ef21b44eb6fe35ed9 (diff)
downloadredis-py-6c70fcdd10cca7de15175a77824009babfac4417.tar.gz
CLIENT REPLY support, available since redis 3.2.0 (#1581)
-rw-r--r--redis/commands.py19
-rw-r--r--tests/conftest.py6
-rw-r--r--tests/test_commands.py13
3 files changed, 38 insertions, 0 deletions
diff --git a/redis/commands.py b/redis/commands.py
index 427f303..4266f9c 100644
--- a/redis/commands.py
+++ b/redis/commands.py
@@ -376,6 +376,25 @@ class Commands:
"Returns the current connection name"
return self.execute_command('CLIENT GETNAME')
+ def client_reply(self, reply):
+ """Enable and disable redis server replies.
+ ``reply`` Must be ON OFF or SKIP,
+ ON - The default most with server replies to commands
+ OFF - Disable server responses to commands
+ SKIP - Skip the response of the immediately following command.
+
+ Note: When setting OFF or SKIP replies, you will need a client object
+ with a timeout specified in seconds, and will need to catch the
+ TimeoutError.
+ The test_client_reply unit test illustrates this, and
+ conftest.py has a client with a timeout.
+ See https://redis.io/commands/client-reply
+ """
+ replies = ['ON', 'OFF', 'SKIP']
+ if reply not in replies:
+ raise DataError('CLIENT REPLY must be one of %r' % replies)
+ return self.execute_command("CLIENT REPLY", reply)
+
def client_id(self):
"Returns the current connection id"
return self.execute_command('CLIENT ID')
diff --git a/tests/conftest.py b/tests/conftest.py
index fe304c2..b9091a9 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -101,6 +101,12 @@ def r(request):
@pytest.fixture()
+def r_timeout(request):
+ with _get_client(redis.Redis, request, socket_timeout=1) as client:
+ yield client
+
+
+@pytest.fixture()
def r2(request):
"A second client for tests that need multiple"
with _get_client(redis.Redis, request) as client:
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 7b6f55e..a283afc 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -478,6 +478,19 @@ class TestRedisCommands:
def test_client_unpause(self, r):
assert r.client_unpause() == b'OK'
+ @skip_if_server_version_lt('3.2.0')
+ def test_client_reply(self, r, r_timeout):
+ assert r_timeout.client_reply('ON') == b'OK'
+ with pytest.raises(exceptions.TimeoutError):
+ r_timeout.client_reply('OFF')
+
+ r_timeout.client_reply('SKIP')
+
+ assert r_timeout.set('foo', 'bar')
+
+ # validate it was set
+ assert r.get('foo') == b'bar'
+
def test_config_get(self, r):
data = r.config_get()
assert 'maxmemory' in data