Skip to content

Commit

Permalink
getdel (redis#1514)
Browse files Browse the repository at this point in the history
  • Loading branch information
AvitalFineRedis authored and chayim committed Jul 25, 2021
1 parent 40bc256 commit 6de60db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,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):
"""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,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)
Expand Down

0 comments on commit 6de60db

Please sign in to comment.