redis MIGRATE command


  Translation results:

英[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 commandsyntax

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 commandexample

先启动两个 Redis 实例,一个使用默认的 6379 端口,一个使用 7777 端口。
$ ./redis-server &[1] 3557
...
$ ./redis-server --port 7777 &[2] 3560...

然后用客户端连上 6379 端口的实例,设置一个键,然后将它迁移到 7777 端口的实例上:
$ ./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

使用另一个客户端,查看 7777 端口上的实例:
$ ./redis-cli -p 7777
redis 127.0.0.1:7777> GET greeting
"Hello from 6379 instance"

Popular Recommendations

Home

Videos

Q&A