From db692b682d68406d9513bb2917696e2f4660e815 Mon Sep 17 00:00:00 2001 From: d3fau1t Date: Fri, 5 May 2023 00:02:58 +0900 Subject: [PATCH 1/5] Add client no-touch --- redis/commands/core.py | 11 +++++++++++ tests/test_commands.py | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/redis/commands/core.py b/redis/commands/core.py index d67291b314..d2e22643e6 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -761,6 +761,17 @@ def client_no_evict(self, mode: str) -> Union[Awaitable[str], str]: """ return self.execute_command("CLIENT NO-EVICT", mode) + def client_no_touch(self, mode: str) -> Union[Awaitable[str], str]: + """ + # Commands sent by the client will alter + # the LRU/LFU of the keys they access. + # When turned on, the current client will not change LFU/LRU stats, + # unless it sends the TOUCH command. + + For more information see https://redis.io/commands/client-no-touch + """ + return self.execute_command("CLIENT NO-TOUCH", mode) + def command(self, **kwargs): """ Returns dict reply of details about all Redis commands. diff --git a/tests/test_commands.py b/tests/test_commands.py index 2b769be34d..6d491fd22b 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -693,6 +693,13 @@ def test_client_no_evict(self, r): with pytest.raises(TypeError): r.client_no_evict() + @pytest.mark.onlynoncluster + @skip_if_server_version_lt("7.2.0") + def test_client_no_touch(self, r): + assert r.client_no_touch("ON") + with pytest.raises(TypeError): + r.client_no_touch() + @pytest.mark.onlynoncluster @skip_if_server_version_lt("3.2.0") def test_client_reply(self, r, r_timeout): From d8f38e82c615b2d376ad965ca1263542ae5025a1 Mon Sep 17 00:00:00 2001 From: Seongchuel Ahn Date: Mon, 8 May 2023 13:01:12 +0900 Subject: [PATCH 2/5] Update redis/commands/core.py Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com> --- redis/commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/commands/core.py b/redis/commands/core.py index d2e22643e6..1a4acb28e8 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -763,7 +763,7 @@ def client_no_evict(self, mode: str) -> Union[Awaitable[str], str]: def client_no_touch(self, mode: str) -> Union[Awaitable[str], str]: """ - # Commands sent by the client will alter + # The command controls whether commands sent by the client will alter # the LRU/LFU of the keys they access. # When turned on, the current client will not change LFU/LRU stats, # unless it sends the TOUCH command. From b5972b19dcbfa4c25a4cf86c55b80b1e8178d606 Mon Sep 17 00:00:00 2001 From: Seongchuel Ahn Date: Mon, 8 May 2023 13:06:40 +0900 Subject: [PATCH 3/5] Update test_commands.py Improve test_client_no_touch --- tests/test_commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_commands.py b/tests/test_commands.py index 6d491fd22b..75f684756e 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -696,7 +696,8 @@ def test_client_no_evict(self, r): @pytest.mark.onlynoncluster @skip_if_server_version_lt("7.2.0") def test_client_no_touch(self, r): - assert r.client_no_touch("ON") + assert r.client_no_touch("ON") == b"OK" + assert r.client_no_touch("OFF") == b"OK" with pytest.raises(TypeError): r.client_no_touch() From 380e3388b8f958db062146f681be60fd2dd685d8 Mon Sep 17 00:00:00 2001 From: Seongchuel Ahn Date: Mon, 8 May 2023 13:12:01 +0900 Subject: [PATCH 4/5] Update test_commands.py Add async version test case --- tests/test_asyncio/test_commands.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_asyncio/test_commands.py b/tests/test_asyncio/test_commands.py index 409934c9a3..6aa6afec90 100644 --- a/tests/test_asyncio/test_commands.py +++ b/tests/test_asyncio/test_commands.py @@ -446,6 +446,14 @@ async def test_client_pause(self, r: redis.Redis): with pytest.raises(exceptions.RedisError): await r.client_pause(timeout="not an integer") + @skip_if_server_version_lt("7.2.0") + @pytest.mark.onlynoncluster + async def test_client_no_touch(self, r: redis.Redis): + assert await r.client_no_touch("ON") == b"OK" + assert await r.client_no_touch("OFF") == b"OK" + with pytest.raises(TypeError): + await r.client_no_touch() + async def test_config_get(self, r: redis.Redis): data = await r.config_get() assert "maxmemory" in data From 56fccf5b6c9db080454ebafc1b3cebab7c1d979c Mon Sep 17 00:00:00 2001 From: Seongchuel Ahn Date: Mon, 8 May 2023 17:34:05 +0900 Subject: [PATCH 5/5] Chore remove whitespace Oops --- tests/test_asyncio/test_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_asyncio/test_commands.py b/tests/test_asyncio/test_commands.py index 6aa6afec90..5d70c6ff12 100644 --- a/tests/test_asyncio/test_commands.py +++ b/tests/test_asyncio/test_commands.py @@ -453,7 +453,7 @@ async def test_client_no_touch(self, r: redis.Redis): assert await r.client_no_touch("OFF") == b"OK" with pytest.raises(TypeError): await r.client_no_touch() - + async def test_config_get(self, r: redis.Redis): data = await r.config_get() assert "maxmemory" in data