diff options
author | Yoshinari Takaoka <mumumu@mumumu.org> | 2015-12-28 06:22:13 +0900 |
---|---|---|
committer | Yoshinari Takaoka <mumumu@mumumu.org> | 2015-12-28 06:22:13 +0900 |
commit | 6e6c3bdedb2998e26d3ce7d0d2c64a57a45bf3cb (patch) | |
tree | 7f68164f59eb18e33f8e4f78e7fefc7eedef6a03 | |
parent | da1378481f963961afab420573eb4130091dd861 (diff) | |
download | redis-py-6e6c3bdedb2998e26d3ce7d0d2c64a57a45bf3cb.tar.gz |
- added replace option to restore command
-rwxr-xr-x | redis/client.py | 7 | ||||
-rw-r--r-- | tests/test_commands.py | 10 |
2 files changed, 15 insertions, 2 deletions
diff --git a/redis/client.py b/redis/client.py index e426abe..295c065 100755 --- a/redis/client.py +++ b/redis/client.py @@ -1031,12 +1031,15 @@ class StrictRedis(object): "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): """ diff --git a/tests/test_commands.py b/tests/test_commands.py index 7293810..352fc2a 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -285,6 +285,16 @@ class TestRedisCommands(object): 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' |