diff options
author | Avital Fine <79420960+AvitalFineRedis@users.noreply.github.com> | 2021-07-25 10:19:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-25 10:19:44 +0300 |
commit | 01b96db203a651ff82598ad66685e487b74b8aac (patch) | |
tree | 61895321662e5dd37d9c844283d07d70a6fc9bac | |
parent | b021f5a15e61ac4217b533443eba0a1c56c03ef3 (diff) | |
download | redis-py-01b96db203a651ff82598ad66685e487b74b8aac.tar.gz |
getdel (#1514)
-rwxr-xr-x | redis/client.py | 9 | ||||
-rw-r--r-- | tests/test_commands.py | 7 |
2 files changed, 16 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index ef3c82c..fe6299f 100755 --- a/redis/client.py +++ b/redis/client.py @@ -1707,6 +1707,15 @@ class Redis: """ 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 18f37d1..b83fe8f 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -758,6 +758,13 @@ class TestRedisCommands: 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) assert r.getex('a') == b'1' |