FailoverRedis
- class sentry_redis_tools.failover_redis.FailoverRedis(*args, _retries=10, _backoff_min=0.2, _backoff_max=5, _backoff_multiplier=2, **kwargs)
Single host redis client implementation with retry logic intended to survive failover events. Retry logic uses capped exponential backoff with jitter.
https://redis.io/commands/failover
Failover sequence:
1. The primary will internally start a CLIENT PAUSE WRITE, which will pause incoming writes and prevent the accumulation of new data in the replication stream. From this point all writes to the primary instance fails with ReadOnlyError.
2. The primary will monitor its replicas, waiting for a replica to indicate that it has fully consumed the replication stream. If the primary has multiple replicas, it will only wait for the first replica to catch up.
3. The primary will then demote itself to a replica. This is done to prevent any dual master scenarios.
4. The previous primary will send a special PSYNC request to the target replica, PSYNC FAILOVER, instructing the target replica to become a primary.
5. Once the previous primary receives acknowledgement the PSYNC FAILOVER was accepted it will unpause its clients.
In addition, the Memorystore for Redis, which is the main target of this implementation states:
When the primary node fails over to the replica, existing connections to the primary endpoint of the instance are dropped. The instance is unavailable for a few seconds while the new primary reconnects. On reconnect, your application is automatically redirected to the new primary node using the same connection string or IP address. You do not need to update your application after a failover.