public class MasterSlave extends Object
This API allows connections to Redis Master/Slave setups which run either Standalone or are managed by Redis Sentinel.
Master-Slave connections incorporate topology discovery and source selection for read operations using
ReadFrom
. Regular Standalone connections using RedisClient.connect()
are single-node
connections without balancing/topology discovery.
Connections can be obtained by providing the RedisClient
, a RedisURI
and a RedisCodec
.
RedisClient client = RedisClient.create();
StatefulRedisMasterSlaveConnection
Master-Slave topologies are either static or semi-static. Redis Standalone instances with attached slaves feature no
failover/HA mechanism and are static setups. Redis Sentinel managed instances are controlled by Redis Sentinel and allow
failover (which include master promotion). The MasterSlave
API supports both mechanisms. The topology is provided by
a TopologyProvider
:
MasterSlaveTopologyProvider
: Topology lookup using the INFO REPLICATION
output. Slaves are listed as
slaveN=...
entries.SentinelTopologyProvider
: Topology lookup using the Redis Sentinel API. In particular SENTINEL SLAVES
output.Constructor and Description |
---|
MasterSlave() |
Modifier and Type | Method and Description |
---|---|
static <K,V> StatefulRedisMasterSlaveConnection<K,V> |
connect(RedisClient redisClient,
RedisCodec<K,V> codec,
RedisURI redisURI)
|
public static <K,V> StatefulRedisMasterSlaveConnection<K,V> connect(RedisClient redisClient, RedisCodec<K,V> codec, RedisURI redisURI)
RedisURI
and the supplied
codec
to encode/decode keys.K
- Key typeV
- Value typeredisClient
- the Redis clientcodec
- Use this codec to encode/decode keys and values, must not be nullredisURI
- the Redis server to connect to, must not be nullCopyright © 2016. All rights reserved.