Before we jump to migration, I want to give an overview regarding when we can use Redis as a database, and how to choose which setup we should go with Master-Slave or Cluster mode.
Redis as a Database
Redis Master-Slave Replication
Replication vs Sharding
- Firstly we needed to create a different Redis Cluster environment. The architecture of the cluster environment was something like
I know the all steps are easy except the second step. Fortunately, redis provides a method of key scanning through which we can scan all the key and take a dump of it and then restore it in the new Redis Server.
- The next step was to update all the services (application) to send all the write operations to both servers(cluster and master-slave). The read commands (GET) will still go to the old setup.
- But still, we don't have the guarantee that all non-expirable data would make it over. So we can run a step to iterate through all of the keys and DUMP/RESTORE them into the new setup.
- Once the new Redis Server looks good we could make the appropriate changes to the application to point solely to the new Redis Server.
To achieve this I have created a python utility in which you have to define the connection details of your old Redis Server and new Redis Server.
You can find the utility here.
I have provided the detail information on using this utility in the README file itself. I guess my experience will help you guys while redis migration.