Permalink
Browse files

Merge pull request #698 from mumumu/add_replace_option_to_restore_com…

…mand

implemented REPLACE modifier of restore command
  • Loading branch information...
2 parents 979891c + 6e6c3bd commit eae07e76b6524e6772be60169549766e7826419a @andymccurdy committed on GitHub Jun 15, 2016
Showing with 15 additions and 2 deletions.
  1. +5 −2 redis/client.py
  2. +10 −0 tests/test_commands.py
View
@@ -1117,12 +1117,15 @@ def renamenx(self, src, dst):
"Rename key ``src`` to ``dst`` if ``dst`` doesn't already exist"
return self.execute_command('RENAMENX', src, dst)
- def restore(self, name, ttl, value):
+ def restore(self, name, ttl, value, replace=False):
"""
Create a key using the provided serialized value, previously obtained
using DUMP.
"""
- return self.execute_command('RESTORE', name, ttl, value)
+ params = [name, ttl, value]
+ if replace:
+ params.append('REPLACE')
+ return self.execute_command('RESTORE', *params)
def set(self, name, value, ex=None, px=None, nx=False, xx=False):
"""
@@ -285,6 +285,16 @@ def test_dump_and_restore(self, r):
r.restore('a', 0, dumped)
assert r['a'] == b('foo')
+ @skip_if_server_version_lt('3.0.0')
+ def test_dump_and_restore_and_replace(self, r):
+ r['a'] = 'bar'
+ dumped = r.dump('a')
+ with pytest.raises(redis.ResponseError):
+ r.restore('a', 0, dumped)
+
+ r.restore('a', 0, dumped, replace=True)
+ assert r['a'] == b('bar')
+
def test_exists(self, r):
assert not r.exists('a')
r['a'] = 'foo'

0 comments on commit eae07e7

Please sign in to comment.