Skip to content

Commit

Permalink
implement unlink command (#250)
Browse files Browse the repository at this point in the history
implement unlink command
  • Loading branch information
zsblevins authored and bmerry committed Aug 15, 2019
1 parent 12b159e commit a01aac5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ generic
* object
* restore
* touch
* unlink
* wait


Expand Down
11 changes: 9 additions & 2 deletions fakeredis/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,7 @@ def swapdb(self, index1, index2):
# Key commands
# TODO: lots

@command((Key(),), (Key(),), name='del')
def del_(self, *keys):
def _delete(self, *keys):
ans = 0
done = set()
for key in keys:
Expand All @@ -922,6 +921,14 @@ def del_(self, *keys):
ans += 1
return ans

@command((Key(),), (Key(),), name='del')
def del_(self, *keys):
return self._delete(*keys)

@command((Key(),), (Key(),), name='unlink')
def unlink(self, *keys):
return self._delete(*keys)

@command((Key(),), (Key(),))
def exists(self, *keys):
ret = 0
Expand Down
6 changes: 6 additions & 0 deletions test_fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4016,6 +4016,12 @@ def test_script(self):
result = script(args=[42])
self.assertEqual(result, b'42')

@redis3_only
def test_unlink(self):
self.redis.set('foo', 'bar')
self.redis.unlink('foo')
self.assertIsNone(self.redis.get('foo'))


class TestFakeRedis(unittest.TestCase):
decode_responses = False
Expand Down
2 changes: 1 addition & 1 deletion test_fakeredis_hypothesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def commands(*args, **kwargs):

# TODO: all expiry-related commands
common_commands = (
commands(st.sampled_from(['del', 'persist', 'type']), keys)
commands(st.sampled_from(['del', 'persist', 'type', 'unlink']), keys)
| commands(st.just('exists'), st.lists(keys))
| commands(st.just('keys'), st.just('*'))
# Disabled for now due to redis giving wrong answers
Expand Down

0 comments on commit a01aac5

Please sign in to comment.