redis 部分数据迁移

在一台服务上面运行下面的脚本

 

 

 

#!/bin/bash
# source http://stackoverflow.com/questions/23222616/copy-all-keys-from-one-db-to-another-in-redis

# 数据所在 redis 中的配置

source_host=XXXXXXXXXXXXXX
source_port=6379
source_password=XXXXXXX
source_db=0

# 要备份的 redis 配置
target_host=XXXXXXXXXXXXXX
target_port=6379
target_password=XXXXXXX
target_db=0

# 将 redis key 以 flow-recharge 开头的 数据 进行迁移
keys_pattern=flow-recharge\*

# copy matching keys
redis-cli -h ${source_host} -p ${source_port} -a ${source_password} -n ${source_db} KEYS "${keys_pattern}" | while read key; do
    echo "Copying ${key}..."
    redis-cli --raw -h ${source_host} -p ${source_port} -a ${source_password} -n ${source_db} DUMP "${key}" | head -c -1 | redis-cli -x -h ${target_host} -p ${target_port} -a ${target_password} -n ${target_db} RESTORE "${key}" 0

# 加过期时间
    #echo "TTL: $(redis-cli --raw -h ${source_host} -p ${source_port} -a ${source_password} -n ${source_db} TTL "${key}")"
    #redis-cli --raw -h ${source_host} -p ${source_port} -a ${source_password} -n ${source_db} TTL "${key}" | head -c -1 | redis-cli -x -h ${target_host} -p ${target_port} -a ${target_password} -n ${target_db} EXPIRE "${key}"
done
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值