diff options
author | Ali-Akber Saifee <ali@indydevs.org> | 2019-12-21 19:15:44 -0800 |
---|---|---|
committer | Ali-Akber Saifee <ali@indydevs.org> | 2019-12-21 19:30:21 -0800 |
commit | 952d5fabb95d10cdd58784549849ae38f8b6e1d9 (patch) | |
tree | 6845e54fb06ca210c0d4919d49a71e8b86c57707 | |
parent | bdda7cd0b1789b5bfc6be186beed24b6cc28b603 (diff) | |
download | pymemcache-952d5fabb95d10cdd58784549849ae38f8b6e1d9.tar.gz |
Add touch method to HashClient (#263)
-rw-r--r-- | pymemcache/client/hash.py | 4 | ||||
-rw-r--r-- | pymemcache/test/test_client_hash.py | 15 | ||||
-rw-r--r-- | pymemcache/test/test_integration.py | 17 |
3 files changed, 36 insertions, 0 deletions
diff --git a/pymemcache/client/hash.py b/pymemcache/client/hash.py index d2a5489..77ea935 100644 --- a/pymemcache/client/hash.py +++ b/pymemcache/client/hash.py @@ -422,6 +422,10 @@ class HashClient(object): def replace(self, key, *args, **kwargs): return self._run_cmd('replace', key, False, *args, **kwargs) + def touch(self, key, *args, **kwargs): + return self._run_cmd('touch', key, False, *args, **kwargs) + + def flush_all(self): for _, client in self.clients.items(): self._safely_run_func(client, client.flush_all, False) diff --git a/pymemcache/test/test_client_hash.py b/pymemcache/test/test_client_hash.py index cea71bd..12e045d 100644 --- a/pymemcache/test/test_client_hash.py +++ b/pymemcache/test/test_client_hash.py @@ -143,6 +143,21 @@ class TestHashClient(ClientTestMixin, unittest.TestCase): assert (result == {b'key1': (b'value1', b'1'), b'key3': (b'value2', b'1')}) + def test_touch_not_found(self): + client = self.make_client([b'NOT_FOUND\r\n']) + result = client.touch(b'key', noreply=False) + assert result is False + + def test_touch_no_expiry_found(self): + client = self.make_client([b'TOUCHED\r\n']) + result = client.touch(b'key', noreply=False) + assert result is True + + def test_touch_with_expiry_found(self): + client = self.make_client([b'TOUCHED\r\n']) + result = client.touch(b'key', 1, noreply=False) + assert result is True + def test_no_servers_left(self): from pymemcache.client.hash import HashClient client = HashClient( diff --git a/pymemcache/test/test_integration.py b/pymemcache/test/test_integration.py index f5dbb1f..47b547d 100644 --- a/pymemcache/test/test_integration.py +++ b/pymemcache/test/test_integration.py @@ -230,6 +230,23 @@ def test_incr_decr(client_class, host, port, socket_module): @pytest.mark.integration() +def test_touch(client_class, host, port, socket_module): + client = client_class((host, port), socket_module=socket_module) + client.flush_all() + + result = client.touch(b'key', noreply=False) + assert result is False + + result = client.set(b'key', b'0', 1, noreply=False) + assert result is True + + result = client.touch(b'key', noreply=False) + assert result is True + + result = client.touch(b'key', 1, noreply=False) + assert result is True + +@pytest.mark.integration() def test_misc(client_class, host, port, socket_module): client = Client((host, port), socket_module=socket_module) client.flush_all() |