Search code examples
springlettuceredis-sentinel

Spring Data Redis - How to detect a failover to resubscribe to channels


I'm using Spring Data Redis with Redis Sentinel and subscribe to keyspace event notifications. How to detect when a switch to a new master occurs as a result of a failover so that I can resubscribe to the required channels?


Solution

  • There is no need to manually detect failovers and resubscribe to channels when that happens, since Lettuce does that by itself (see StatefulRedisPubSubConnectionImpl#activated()).