从具有多个数据库的实例中复制单个Redis数据库 [英] Replicate a single Redis database from an instance that has multiple databases

查看:388
本文介绍了从具有多个数据库的实例中复制单个Redis数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Redis实例,其中有两个数据库。现在,我想设置第二个实例,并复制第一个实例,但是第二个实例应该只有一个数据库并仅从第一个实例复制db 0。
尝试执行此操作时(第二个实例设置 slaveof ... ),我在Redis日志文件中收到以下错误消息:

I have one Redis instance that has two databases. Now I want to set up a second instance and replicate the first instance, but the second instance should only have one database and replicate only db 0 from the first instance. When I try to do it (set slaveof ... for the second instance) I get the following error message in the Redis log file:

FATAL: Data file was created with a Redis server configured to handle more than 1 databases. Exiting

我尝试使用 redis-dump ,但是当我尝试将生成的转储导入新实例时出现错误。 (我认为与2 db与1 db无关,而是redis-dump中的一个错误,该错误仍在alpha中。

I tried using redis-dump but I get an error when I try to import the generated dump into the new instance. (not related to 2 dbs vs. 1 db I think, rather a bug in redis-dump, which is still in alpha.

该怎么办?

推荐答案

这是我的实现方式(在Gurpartap Singh的帮助下):

This is how I achieved it (with help of Gurpartap Singh):


  • 使用 databases 2 配置第二个Redis实例,就像第一个实例

  • 复制第一个实例一样(请参见 http://redis.io/topics/replication

  • 打开到第二个Redis实例的命令行(使用redis-cli)

  • 在Redis CLI上:SELECT 1(选择第二个数据库)

  • 在Redis上CLI:FLUSHDB(删除第二个数据库中的所有键)

  • 在Redis CLI上:SAVE(将数据集保存到磁盘)

  • 退出Redis CLI并停止Redis

  • 将配置更改为数据库1

  • 再次启动Redis

  • Configure the second Redis instance with databases 2 just like the first one
  • Replicate the first instance (see http://redis.io/topics/replication)
  • Open a command line to the second Redis instance (using redis-cli)
  • On Redis CLI: SELECT 1 (select second db)
  • On Redis CLI: FLUSHDB (delete all keys in the second db)
  • On Redis CLI: SAVE (saves the dataset to disk)
  • Exit Redis CLI and stop Redis
  • Change configuration to databases 1
  • Start Redis again

此时,您应该有一个正在运行的Redis实例,并且只有一个d b(原始Redis实例中的db 0)

At this point you should have a running Redis instance with only one db (db 0 from the original Redis instance)

此处的键是,当我们删除第二个db中的所有键,然后将数据集保存到磁盘时,产生转储只有一个分贝。 (感谢古尔巴塔普·辛格的提示)

The key here is that when we delete all keys in the second db and then save the dataset to disk, the resulting dump only has one db. (Thanks for the hint to Gurpartap Singh)

这篇关于从具有多个数据库的实例中复制单个Redis数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆