In order to promote a Redis replica to master, you'll need to follow certain steps. This process is typically required when the current master is not available or in other scenarios where you want to switch over to a different node.
Here are the steps:
Disconnect the replica from the master: You can do this using the
replicaof no one command. This will stop the replication and therefore allow the current replica to accept write commands.
Check if the promotion was successful: Use the
info replication command. If the role is 'master', then your replica has been promoted successfully.
The output should begin with something like this:
3. Connect other replicas (if any) to the new master: For every other replica, use the
replicaof <new_master_host> <new_master_port> command.
redis-cli -h <slave_host> -p <slave_port> replicaof <new_master_host> <new_master_port>
Please note that replica promotion is a manual process and during this process there can be data inconsistencies due to asynchronous nature of Redis replication.
It's also important to mention sentinel mode, which is a more robust way to handle failover, as it automates this process. However, setting up and maintaining a sentinel system can be more complex than managing a simple master-replica setup.