-
Notifications
You must be signed in to change notification settings - Fork 985
Redis Sentinel
When using Lettuce, you can interact with Redis Sentinel and Redis Sentinel-managed nodes in multiple ways:
-
Direct connection to Redis Sentinel, for issuing Redis Sentinel commands
-
Using Redis Sentinel to connect to a master
-
Using Redis Sentinel to connect to master nodes and replicas through the Master-Replica API.
In both cases, you need to supply a RedisURI
since the Redis Sentinel integration supports multiple Sentinel hosts to provide high availability.
Please note: Redis Sentinel (Lettuce 3.x) integration provides only asynchronous connections and no connection pooling.
Lettuce exposes an API to interact with Redis Sentinel nodes directly. This is useful for performing administrative tasks using Lettuce. You can monitor new master nodes, query master addresses, replicas and much more. A connection to a Redis Sentinel node is established by RedisClient.connectSentinel()
. Use a Publish/Subscribe connection to subscribe to Sentinel events.
One or more Redis Sentinels can monitor Redis instances . These Redis instances are usually operated together with a replica of the Redis instance. Once the master goes down, the replica is promoted to a master. Once a master instance is not reachable anymore, the failover process is started by the Redis Sentinels. Usually, the client connection is terminated. The disconnect can result in any of the following options:
-
The master comes back: The connection is restored to the Redis instance
-
A replica is promoted to a master: Lettuce performs an address lookup using the
masterId
. As soon as the Redis Sentinel provides an address the connection is restored to the new Redis instance
Read more at http://redis.io/topics/sentinel
RedisURI redisUri = RedisURI.create("redis://sentinelhost1:26379");
RedisClient client = new RedisClient(redisUri);
RedisSentinelAsyncConnection<String, String> connection = client.connectSentinelAsync();
Map<String, String> map = connection.master("mymaster").get();
RedisURI redisUri = RedisURI.Builder.sentinel("sentinelhost1", "mymaster").withSentinel("sentinelhost2").build();
RedisClient client = RedisClient.create(redisUri);
RedisConnection<String, String> connection = client.connect();
Note
|
Every time you connect to a Redis instance using Redis Sentinel, the Redis master is looked up using a new connection to a Redis Sentinel. This can be time-consuming, especially when multiple Redis Sentinels are used and one or more of them are not reachable. |
Lettuce documentation was moved to https://redis.github.io/lettuce/overview/
Intro
Getting started
- Getting started
- Redis URI and connection details
- Basic usage
- Asynchronous API
- Reactive API
- Publish/Subscribe
- Transactions/Multi
- Scripting and Functions
- Redis Command Interfaces
- FAQ
HA and Sharding
Advanced usage
- Configuring Client resources
- Client Options
- Dynamic Command Interfaces
- SSL Connections
- Native Transports
- Unix Domain Sockets
- Streaming API
- Events
- Command Latency Metrics
- Tracing
- Stateful Connections
- Pipelining/Flushing
- Connection Pooling
- Graal Native Image
- Custom commands
Integration and Extension
Internals