est*_*ani 32
如果由于您的redis版本而无法使用MIGRATE COPY,则可能需要单独复制每个密钥,这需要更长的时间,但不需要您登录到计算机本身,并允许您将数据从一个数据库移动到另一个数据库.这是我如何将所有键从一个数据库复制到另一个数据库(但不保留ttls)
#set connection data accordingly
source_host=localhost
source_port=6379
source_db=0
target_host=localhost
target_port=6379
target_db=1
#copy all keys without preserving ttl!
redis-cli -h $source_host -p $source_port -n $source_db keys \* | while read key; do echo "Copying $key"; redis-cli --raw -h $source_host -p $source_port -n $source_db DUMP "$key" | head -c -1|redis-cli -x -h $target_host -p $target_port -n $target_db RESTORE "$key" 0; done
Run Code Online (Sandbox Code Playgroud)
密钥不会被覆盖,因为在复制之前删除密钥或在启动之前刷新整个数据库.
最新解决方案:
使用Redislabs提供的RIOT开源命令行工具复制数据。
参考: https: //developer.redis.com/riot/#_replicate_dump_and_restore
GitHub项目链接: https: //github.com/redis-developer/riot
如何安装: https: //developer.redis.com/riot/#_install
# Source Redis db
SH=test1-redis.com
SP=6379
# Target Redis db
TH=test1-redis.com
TP=6379
# Copy from db0 to db1 (standalone Redis db, Or cluster mode disabled)
#
riot-redis -h $SH -p $SP --db 0 replicate -h $TH -p $TP --db 1 --batch 10000 \
--scan-count 10000 \
--threads 4 \
--reader-threads 4 \
--reader-batch 500 \
--reader-queue 2000 \
--reader-pool 4
Run Code Online (Sandbox Code Playgroud)
RIOT 速度更快,支持多线程,并且可以很好地与跨环境 Redis 数据复制(AWS Elasticache、Redis OSS 和 Redislabs)配合使用。
| 归档时间: |
|
| 查看次数: |
22196 次 |
| 最近记录: |