Data migration between redis

Redis comes with commands

 The parameters of migrate are explained one by one:
Host: The IP address of the target Redis.
· Port: The port of the target Redis.
·Key|"": Before Redis3.0.6, migrate only supports the migration of one key, so here is the key to be migrated, but after Redis3.0.6, it supports the migration of multiple keys. If you need to migrate multiple keys currently, this The place is an empty string "".
· Destination-db: The database index of the target Redis. For example, if you want to migrate to database 0, write 0 here.
·Timeout: The timeout period of migration (in milliseconds).
· [Copy]: If you add this option, the source key will not be deleted after migration.
·[Replace]: If you add this option, migrate will migrate normally for data overwriting regardless of whether the target Redis exists or not.
·[Keys key[key...]]: To migrate multiple keys, for example, to migrate key1, key2, key3, fill in "keys key1 key2 key3" here.

 migrate 127.0.0.1 6379 "" 10000 keys key1 key2 key3 

Recommended redis-migrate-tool migration method

Install redis-migrate-tool

rely

yum -y install automake libtool autoconf bzip2 git
git clone https://github.com/tanruixing88/redis-migrate-tool.git
cd redis-migrate-tool
autoreconf -fvi
./configure
make
src/redis-migrate-tool -h

 

 

rmt.conf

[source]
type: single
hash: fnv1a_64
hash_tag: "{}"
distribution: ketama
servers : 
-127.0.0.1:6379

[target]
type: single
servers:
-127.0.0.1:6380

[common]
listen: 0.0.0.0:8888

Migration command:

/root/redis-migrate-tool/src/redis-migrate-tool -c rmt.conf -o log -d

 

 

./redis-cli -h 127.0.0.1 -p 8888 View process
 

This process will continue to run in the background. After the data is tied, let the business side stop writing the old redis library during the low peak period, and change the connection method to this new library. (It is recommended that the redis master and slave use sentinel. High availability). After confirming that there is no problem, the DBA kills the redis-migrate-tool process, and the entire redis migration process ends. 

 

Configuration instructions:

[source]/[target]:

type:
single:单独的redis实例
twemproxy:twemproxy集群
redis cluster:redis集群
rdb file:.rdb文件
aof file:.aof文件
servers:redis地址组,如果type:twemproxy,则为twemproxy配置文件,如果type:rdb file,则为rdb文件名。
redis_auth:连接redis服务的认证auth。
timeout:读写redis服务的超时时间(ms),默认为120000ms
hash:哈希方法名。仅当type:twemproxy有效。可以为one_at_a_time、md5、crc16、crc32、crc32a、fnv1_64、fnv1a_64、fnv1_32、fnv1a_32、hsieh、murmur、jenkins。
hash_tag:用来哈希的关键key的两个字符,例如"{}" 或 “$$”。仅当type:twemproxy有效。只要标签内的关键key是相同的,能够将不同的键映射到同一服务器。
distribution:键的分布模式。仅当type:twemproxy有效。可以为 ketama、modula、random。
[common]:

listen:监听的地址和端口。默认为127.0.0.1:8888
max_clients:可监听端口的最大连接数。默认为100
threads:工具可用的最多线程数。默认为cpu内核数。
step:解析请求的步数。默认为1,数字越大,迁移越快,需要越多的内存。
mbuf_size:请求的缓存大小(M),默认为512M
noreply:是否检查目标组的回复,默认为false
source_safe:是否保护源组机器的内存安全。默认为true,工具将允许在源组的同一台机器同时只有一个redis生成.rdb。
dir:工作目录。用来存储文件,例如rdb文件,默认为当前目录。
filter:过滤不符合表达式的Key,默认为NULL,支持通配符为glob-style风格
? :1个任意字符。例如 h?llo 匹配 hello, hallo , hxllo
* :0个或多个任意字符。例如 h*llo 匹配 hllo , heeeello
[characters]:匹配任意一个方括号内的字符,比如[abc],要么匹配a,要么匹配b,要么匹配c。例如 h[ae]llo 匹配 hello , hallo, 但不匹配 hillo。
[^character]:排除方括号内的字符。例如h[^e]llo 匹配 hallo, hbllo, … 但不匹配 hello。
[character-character]:表示2个字符范围内的都可以匹配,如[a-z],[0-9]。例如h[a-b]llo 匹配 hallo 和 hbllo。
\用来转移特殊字符。

 

Guess you like

Origin blog.csdn.net/qq_39313596/article/details/112481214