zoukankan      html  css  js  c++  java
  • Redis迁移键

    迁移键:

    move key db 用于在Redis内部进行数据迁移

    dump key + restore key ttl value 可以实现在不同的Redis实例之间进行数据迁移

    127.0.0.1:6379> dump name

    "x00x05allenax00x82x9a*T/xb9x9bx87"

    127.0.0.1:6379> dump age

    "x00xc0!ax006.9xfaQx06xe8 "

    127.0.0.1:6379> dump pass

    "x00x06abc123ax00x90 xe8x1bxf2xd4x8bxec"

    192.168.1.122:6379> restore name 0 "x00x05allenax00x82x9a*T/xb9x9bx87"

    OK

    192.168.1.122:6379> restore age 0 "x00xc0!ax006.9xfaQx06xe8 "

    OK

    192.168.1.122:6379> restore pass 0 "x00x06abc123ax00x90 xe8x1bxf2xd4x8bxec"

    OK

    migrate host port key|"" destination-db timeout [copy] [replace] [keys key [key ...]]

    127.0.0.1:6379> migrate 192.168.1.122 6379 name 0 5000  默认是删除源库的键值

    OK

    127.0.0.1:6379> migrate 192.168.1.122 6379 "" 0 5000 copy keys age pass  copyreplace源库不删除键值

    OK

    # cat redis_mv.sh

    #!/bin/bash

    redis-cli -h 172.20.0.1 -p 6379 -a password -n 0 keys "*" | while read key

    do

        redis-cli -h 172.20.0.1 -p 6379 -a password -n 0 --raw dump $key | perl -pe 'chomp if eof' | redis-cli -h 172.20.0.2 -p 6379 -a password -n 1 -x restore $key 0

        echo "migrate key $key"

    done

    #!/bin/bash

    #redis ip

    src_ip=192.168.0.1

    #redis port

    src_port=6379

    #redis 源库

    src_db=11

    #redis 目的ip

    dest_ip=192.168.0.1

    #redis 目的port

    dest_port=6379

    #redis 目的

    dest_db=6

    #redis 密码

    pw=123456

    #要迁移的key前缀

    #key_prefix=com.example.test

    redis-cli -h $src_ip -p $src_port -a $pw -n $src_db keys "*" | while read key

    do

        redis-cli -h $src_ip -p $src_port -a $pw -n $src_db --raw dump $key | perl -pe 'chomp if eof' | redis-cli -h $dest_ip -p $dest_port -a $pw -n $dest_db -x restore $key 0

        echo "migrate key $key"

    done

    #!/bin/bash

    #redis ip

    src_ip=192.168.0.1

    #redis port

    src_port=6379

    #redis 源库

    src_db=1

    #redis 目的ip

    dest_ip=192.168.0.1

    #redis 目的port

    dest_port=6379

    #redis 目的

    dest_db=3

    #redis 密码

    pw=123456

    #要遍历的key

    k=(medical_record:id medical_record_attachment:id patient_family_present:id patient_present:id patient_disease:id family_disease:id patient_allergy:id history_allergy:id)

    #要迁移的key前缀

    #key_prefix=com.example.test

    for loop in ${k[*]}

    do

        redis-cli -h $src_ip -p $src_port -a $pw -n $src_db --raw dump $loop | perl -pe 'chomp if eof' | redis-cli -h $dest_ip -p $dest_port -a $pw -n $dest_db -x restore $loop 0

        echo "The value is: $loop"

    done

  • 相关阅读:
    FormsAuthentication.HashPasswordForStoringInConfigFile方法再.net core中的替代代码
    git 删除分支和回退到以前某个提交版本
    .net core 2.1控制台使用Quartz.net实现定时任务执行
    CodeForces
    CodeForces
    CCF 201709-2 公共钥匙盒
    POJ
    CodeForces
    (转)Django vs Flask vs Pyramid: Choosing a Python Web Framework
    (转)Seven Ways of Centering With CSS
  • 原文地址:https://www.cnblogs.com/allenhu320/p/11339901.html
Copyright © 2011-2022 走看看