MIGRATE host port key|"" destination-db timeout [COPY] [REPLACE] [AUTH password] [KEYS key [key …]]

    Time complexity: This command actually executes a DUMP+DEL in the source instance, and a RESTORE in the target instance. See the pages of these commands for time complexity. Also an O(N) data transfer between the two instances is performed.

    Atomically transfer a key from a source Redis instance to a destination Redis instance. On success the key is deleted from the original instance and is guaranteed to exist in the target instance.

    The command is atomic and blocks the two instances for the time required to transfer the key, at any given time the key will appear to exist in a given instance or in the other instance, unless a timeout error occurs. In 3.2 and above, multiple keys can be pipelined in a single call to by passing the empty string ("") as key and adding the KEYS clause.

    The command internally uses to generate the serialized version of the key value, and RESTORE in order to synthesize the key in the target instance. The source instance acts as a client for the target instance. If the target instance returns OK to the command, the source instance deletes the key using DEL.

    needs to perform I/O operations and to honor the specified timeout. When there is an I/O error during the transfer or if the timeout is reached the operation is aborted and the special error - returned. When this happens the following two cases are possible:

    • The key may be on both the instances.
    • The key may be only in the source instance.

    It is not possible for the key to get lost in the event of a timeout, but the client calling MIGRATE, in the event of a timeout error, should check if the key is also present in the target instance and act accordingly.

    When any other error is returned (starting with ERR) guarantees that the key is still only present in the originating instance (unless a key with the same name was also already present on the target instance).

    If there are no keys to migrate in the source instance NOKEY is returned. Because missing keys are possible in normal conditions, from expiry for example, isn't an error.

    In order to enable this form, the KEYS option is used, and the normal key argument is set to an empty string. The actual key names will be provided after the argument itself, like in the following example:

    When this form is used the NOKEY status code is only returned when none of the keys is present in the instance, otherwise the command is executed, even if just a single key exists.

    • — Replace existing key on the remote instance.
    • KEYS — If the key argument is an empty string, the command will instead migrate all the keys that follow the option (see the above section for more info).

    COPY and REPLACE are available only in 3.0 and above. KEYS is available starting with Redis 3.0.6. is available starting with Redis 4.0.7.

    Simple string reply: The command returns OK on success, or if no keys were found in the source instance.