diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2018-11-13 12:11:30 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-13 12:11:30 -0800 |
commit | 69effc2464fada8a51658f97d8a251b2e736e34d (patch) | |
tree | 555f72e1aa6583d2bb46b1df29e222d06fd48be2 | |
parent | f2edf59dc5b130a141877c32c0d3236c9f14f77b (diff) | |
parent | 954bc4f28ed2109c40daf93654c210b44f8cf07b (diff) | |
download | redis-py-69effc2464fada8a51658f97d8a251b2e736e34d.tar.gz |
Merge pull request #1064 from andymccurdy/migrate
add migrate command
-rwxr-xr-x | redis/client.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index deb12ad..94853b6 100755 --- a/redis/client.py +++ b/redis/client.py @@ -916,6 +916,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(Token.get_token('COPY')) + if replace: + pieces.append(Token.get_token('REPLACE')) + if auth: + pieces.append(Token.get_token('AUTH')) + pieces.append(auth) + pieces.append(Token.get_token('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) |