Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 40a/f5e3f91d792abffaba1749068bfd1ecb to your computer and use it in GitHub Desktop.
Save 40a/f5e3f91d792abffaba1749068bfd1ecb to your computer and use it in GitHub Desktop.
Redis - High Availability - Manual Failover

Waiting until the support for slave-read-only on StackExchange.Redis, I would like to share my solution to fail-over a node with a minimum write interruption, maintaining data consistency, reducing (eliminating?) possible false write acknowledgment (on the node that is failing). You can lose some write because there's a window where both nodes are slaves. I feel that you can still have some false write ack because you can receive an ack while setting the master as slave and that write could be lost.

redis-slaveof-kvs01.txt

MULTI
SLAVEOF kvs01 6379
CONFIG REWRITE
PUBLISH "__Booksleeve_MasterChanged" "*"
EXEC

redis-slaveof-kvs02.txt

MULTI
SLAVEOF kvs02 6379
CONFIG REWRITE
PUBLISH "__Booksleeve_MasterChanged" "*"
EXEC

redis-slaveof-no-one.txt

MULTI
SLAVEOF NO ONE
CONFIG REWRITE
PUBLISH "__Booksleeve_MasterChanged" "*"
EXEC

and these are the couple of batch that I'm using on windows, but actually I think they work as is in linux too:

redis-failover-to-kvs01.bat

redis-cli -h kvs02 --pipe < redis-slaveof-kvs01.txt
redis-cli -h kvs01 --pipe < redis-slaveof-no-one.txt

redis-failover-to-kvs02.bat

redis-cli -h kvs01 --pipe < redis-slaveof-kvs02.txt
redis-cli -h kvs02 --pipe < redis-slaveof-no-one.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment