英[ma??gre?t] 美[?ma?gre?t]
vi.Move; migrate, move to; migrate with the seasons
vt. To migrate; to transplant
Third person singular: migrates Present participle: migrating Past tense: migrated Past participle: migrated
redis MIGRATE command syntax
Function:Atomicly transfer the key from the current instance to the specified database of the target instance. Once the transfer is successful, the key is guaranteed to appear on the target instance, and the key on the current instance will be deleted. .
Syntax: MIGRATE host port key destination-db timeout [COPY] [REPLACE]
Description: MIGRATE command needs to be executed within the given time Complete the IO operation within the specified time. If an IO error occurs while transferring data, or the timeout is reached, the command stops execution and returns a special error: IOERR .
Available versions: >= 2.6.0
Time complexity: This command actually executes the DUMP command and the DEL command on the source instance , execute the RESTORE command on the target instance. Check the documentation of the above command to see the detailed complexity description. The complexity of transmitting key data between two instances is O(N).
Return: Return OK when the migration is successful, otherwise return the corresponding error.
redis MIGRATE command example
先啟動(dòng)兩個(gè) Redis 實(shí)例,一個(gè)使用默認(rèn)的 6379 端口,一個(gè)使用 7777 端口。 $ ./redis-server &[1] 3557 ... $ ./redis-server --port 7777 &[2] 3560... 然后用客戶端連上 6379 端口的實(shí)例,設(shè)置一個(gè)鍵,然后將它遷移到 7777 端口的實(shí)例上: $ ./redis-cliredis 127.0.0.1:6379> flushdb OK redis 127.0.0.1:6379> SET greeting "Hello from 6379 instance" OK redis 127.0.0.1:6379> MIGRATE 127.0.0.1 7777 greeting 0 1000 OK redis 127.0.0.1:6379> EXISTS greeting # 遷移成功后 key 被刪除(integer) 0 使用另一個(gè)客戶端,查看 7777 端口上的實(shí)例: $ ./redis-cli -p 7777 redis 127.0.0.1:7777> GET greeting "Hello from 6379 instance"