summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2018-11-12 14:35:18 -0800
committerAndy McCurdy <andy@andymccurdy.com>2018-11-12 14:35:18 -0800
commitd9f2c837920e644d65fbdb7239955e4c9902515b (patch)
treec3f884196eee0de2548b85d2c5e27375fb02d080
parent27df0332608f5fa02406890ecfc0a99126ef4805 (diff)
downloadredis-py-d9f2c837920e644d65fbdb7239955e4c9902515b.tar.gz
add migrate command
-rwxr-xr-xredis/client.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py
index d82078e..1c8eb76 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -891,6 +891,41 @@ class StrictRedis(object):
"""
return self.execute_command('LASTSAVE')
+ def migrate(self, host, port, keys, destination_db, timeout,
+ copy=False, replace=False, auth=None):
+ """
+ Migrate 1 or more keys from the current Redis server to a different
+ server specified by the ``host``, ``port`` and ``destination_db``.
+
+ The ``timeout``, specified in milliseconds, indicates the maximum
+ time the connection between the two servers can be idle before the
+ command is interrupted.
+
+ If ``copy`` is True, the specified ``keys`` are NOT deleted from
+ the source server.
+
+ If ``replace`` is True, this operation will overwrite the keys
+ on the destination server if they exist.
+
+ If ``auth`` is specified, authenticate to the destination server with
+ the password provided.
+ """
+ keys = list_or_args(keys, [])
+ if not keys:
+ raise RedisError('MIGRATE requires at least one key')
+ pieces = []
+ if copy:
+ pieces.append('COPY')
+ if replace:
+ pieces.append('REPLACE')
+ if auth:
+ pieces.append('AUTH')
+ pieces.append(auth)
+ pieces.append('KEYS')
+ pieces.extend(keys)
+ return self.execute_command('MIGRATE', host, port, '', destination_db,
+ timeout, *pieces)
+
def object(self, infotype, key):
"Return the encoding, idletime, or refcount about the key"
return self.execute_command('OBJECT', infotype, key, infotype=infotype)