diff --git a/redis/client.py b/redis/client.py index 57932b9f73..fe84d5caee 100755 --- a/redis/client.py +++ b/redis/client.py @@ -1697,6 +1697,15 @@ def get(self, name): """ return self.execute_command('GET', name) + def getdel(self, name): + """ + Get the value at key ``name`` and delete the key. This command + is similar to GET, except for the fact that it also deletes + the key on success (if and only if the key's value type + is a string). + """ + return self.execute_command('GETDEL', name) + def getex(self, name, ex=None, px=None, exat=None, pxat=None, persist=False): """ diff --git a/tests/test_commands.py b/tests/test_commands.py index 27117e3188..351d90c8a3 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -733,6 +733,13 @@ def test_get_and_set(self, r): assert r.get('integer') == str(integer).encode() assert r.get('unicode_string').decode('utf-8') == unicode_string + @skip_if_server_version_lt('6.2.0') + def test_getdel(self, r): + assert r.getdel('a') is None + r.set('a', 1) + assert r.getdel('a') == b'1' + assert r.getdel('a') is None + @skip_if_server_version_lt('6.2.0') def test_getex(self, r): r.set('a', 1)