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
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.
What to do?
Redis uses asynchronous replication, with asynchronous replica-to-master acknowledges of the amount of data processed. A master can have multiple replicas. Replicas are able to accept connections from other replicas.
Redis comes with support for multiple databases, which is very similar to the concept in SQL databases. In SQL databases, such as MySQL, PostgreSQL, and Oracle, you can define a name for your databases. However, Redis databases are represented by numbers.
Using multiple databases in a single instance may be useful in the following scenario: Different copies of the same database could be used for production, development or testing using real-time data. People may use replica to clone a redis instance to achieve the same purpose.
This is how I achieved it (with help of Gurpartap Singh):
databases 2
just like the first onedatabases 1
At this point you should have a running Redis instance with only one db (db 0 from the original Redis instance)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With