redis migrate data

Clean up the memcached cache: first telnet to memcache, then "flush_all" to clear the cache, and finally quit exits.

Redis data migration: Migrate data from one redis to another redis. Redis provides three ways to meet the needs of data migration, namely move, dump+restore, and migrate.

1.1.1 move key db

Redis supports multiple databases, and multiple databases are isolated from each other in terms of data. move key db is to migrate the specified key from the source database to the target database. Since multiple databases are not recommended in production environments, this command is rarely used.

 

1.1.2 dump+restore

Command: source REDIS: dump key

     Target redis: restore keyttl value where ttl represents the expiration time, in milliseconds. 0 means not expired

Implementation principle:

Dump+restore can realize data migration between different redis instances.

(1) On the source Redis, the dump command will serialize the key value in RDB format.

(2) On the target Redis, the restore command will restore the serialized value above, where ttl represents the expiration time, if ttl is 0, it means that there is no expiration time

 Precautions:

(1) The entire migration process is not atomic, but is done through client-side distribution.

(2) The migration process is to open the redis client of two instances, and put the serialized value of the source REDIS to the target REDIS instance client for operation, not to transmit between the source Redis and the target Redis

1.1.3 migrate

The migrate command is atomic, just execute the migrate command on the source redis instance. Migrate's command transfer happens directly between the source redis and target redis instances.

命令:migrate host port key |’’ destination-db timeout [copy] [replace][keyskey[key…]]

Options: host: IP address of target redis

     Port: the port number of the target redis

     key|'''': Before Redis 3.06, migrate only supports migrating one key, so here is the key to be migrated.

 After Redis 3.06, multiple keys can be migrated. If multiple keys are migrated, fill in the empty string ''''

     destination-db: target database index, for example, to migrate to database 0, write 0 here

     timeout: Migration timeout (in milliseconds)

     [copy]: Adding this option does not delete source keys after migration

     [replace]: After adding this option, regardless of whether the key exists in the target redis, the data will be migrated normally for data overwriting

      [keys key[key…]]: To migrate multiple keys, for example, to migrate k1k2 k3, fill in keys key1 key2 key3 here, and return nokey when all keys do not exist on the source instance

For example: migrate 10.3.34.101 6378 010000 copy keys mi aa

Migrate the two elements of mi aa to database 0 of the 10.3.34.101 6378 instance, and the two keys of the source instance mi aa are still retained.

In the java program, you can get all the matching keys of the old redis source according to *, and set the values ​​to the new redis one by one.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326455918&siteId=291194637