Skip to content

Commit 01b96db

Browse files
getdel (#1514)
1 parent b021f5a commit 01b96db

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

redis/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,15 @@ def get(self, name):
17071707
"""
17081708
return self.execute_command('GET', name)
17091709

1710+
def getdel(self, name):
1711+
"""
1712+
Get the value at key ``name`` and delete the key. This command
1713+
is similar to GET, except for the fact that it also deletes
1714+
the key on success (if and only if the key's value type
1715+
is a string).
1716+
"""
1717+
return self.execute_command('GETDEL', name)
1718+
17101719
def getex(self, name,
17111720
ex=None, px=None, exat=None, pxat=None, persist=False):
17121721
"""

tests/test_commands.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,13 @@ def test_get_and_set(self, r):
757757
assert r.get('integer') == str(integer).encode()
758758
assert r.get('unicode_string').decode('utf-8') == unicode_string
759759

760+
@skip_if_server_version_lt('6.2.0')
761+
def test_getdel(self, r):
762+
assert r.getdel('a') is None
763+
r.set('a', 1)
764+
assert r.getdel('a') == b'1'
765+
assert r.getdel('a') is None
766+
760767
@skip_if_server_version_lt('6.2.0')
761768
def test_getex(self, r):
762769
r.set('a', 1)

0 commit comments

Comments
 (0)