Class RedisSentinelConfiguration
java.lang.Object
org.springframework.data.redis.connection.RedisSentinelConfiguration
- All Implemented Interfaces:
RedisConfiguration
,RedisConfiguration.SentinelConfiguration
,RedisConfiguration.WithAuthentication
,RedisConfiguration.WithDatabaseIndex
,RedisConfiguration.WithPassword
public class RedisSentinelConfiguration
extends Object
implements RedisConfiguration, RedisConfiguration.SentinelConfiguration
Configuration
class used to set up a RedisConnection
with
RedisConnectionFactory
for connecting to Redis Sentinel(s).
Useful when setting up a highly available Redis environment.- Since:
- 1.4
- Author:
- Christoph Strobl, Thomas Darimont, Mark Paluch, Vikas Garg, John Blum, Samuel Klose, Mustapha Zorgati
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.data.redis.connection.RedisConfiguration
RedisConfiguration.ClusterConfiguration, RedisConfiguration.DomainSocketConfiguration, RedisConfiguration.SentinelConfiguration, RedisConfiguration.StaticMasterReplicaConfiguration, RedisConfiguration.WithAuthentication, RedisConfiguration.WithDatabaseIndex, RedisConfiguration.WithDomainSocket, RedisConfiguration.WithHostAndPort, RedisConfiguration.WithPassword
-
Constructor Summary
ConstructorDescriptionCreates a new, defaultRedisSentinelConfiguration
.RedisSentinelConfiguration
(String master, Set<String> sentinelHostAndPorts) Creates a newRedisSentinelConfiguration
for givenhostPort
combinations.RedisSentinelConfiguration
(PropertySource<?> propertySource) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addSentinel
(RedisNode sentinel) Add sentinel.boolean
int
Get the database index to use.Get the Sentinel master node.Get the RedisPassword to use when connecting.Returns theRedisPassword
to use when connecting to a Redis Sentinel.Returns anCollections.unmodifiableSet(Set)
of Sentinels.Get the username to use when connecting.Get the username to use when connecting.int
hashCode()
static RedisSentinelConfiguration
of
(PropertySource<?> propertySource) Construct a newRedisSentinelConfiguration
from the givenPropertySource
.void
setDatabase
(int index) Set the database index to use.void
Set the master node.void
setPassword
(RedisPassword password) Create and set aRedisPassword
for givenString
.void
setSentinelPassword
(RedisPassword sentinelPassword) Set aRedisPassword
to be used when authenticating with Redis Sentinel.void
setSentinels
(Iterable<RedisNode> sentinels) Set Sentinels to connect to.void
setSentinelUsername
(String sentinelUsername) Create and set a username with the givenString
.void
setUsername
(String username) Create and set a username with the givenString
.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.data.redis.connection.RedisConfiguration
getDatabaseOrElse, getPasswordOrElse
Methods inherited from interface org.springframework.data.redis.connection.RedisConfiguration.SentinelConfiguration
getDataNodePassword, getDataNodeUsername, setMaster, setSentinelPassword, setSentinelPassword
Methods inherited from interface org.springframework.data.redis.connection.RedisConfiguration.WithAuthentication
setPassword, setPassword
-
Constructor Details
-
RedisSentinelConfiguration
public RedisSentinelConfiguration()Creates a new, defaultRedisSentinelConfiguration
. -
RedisSentinelConfiguration
Creates a newRedisSentinelConfiguration
for givenhostPort
combinations.sentinelHostAndPorts[0] = 127.0.0.1:23679 sentinelHostAndPorts[1] = 127.0.0.1:23680 ...
- Parameters:
sentinelHostAndPorts
- must not be null.- Since:
- 1.5
-
RedisSentinelConfiguration
Deprecated.since 3.3, useof(PropertySource)
instead. This constructor will be made private in the next major release.Creates a newRedisSentinelConfiguration
looking up configuration values from the givenPropertySource
.spring.redis.sentinel.master=myMaster spring.redis.sentinel.nodes=127.0.0.1:23679,127.0.0.1:23680,127.0.0.1:23681
- Parameters:
propertySource
- must not be null.- Since:
- 1.5
-
-
Method Details
-
of
Construct a newRedisSentinelConfiguration
from the givenPropertySource
.- Parameters:
propertySource
- must not be null.- Returns:
- a new
RedisSentinelConfiguration
configured from the givenPropertySource
. - Since:
- 3.3
-
setSentinels
Set Sentinels to connect to.- Parameters:
sentinels
- must not be null.
-
getSentinels
Description copied from interface:RedisConfiguration.SentinelConfiguration
Returns anCollections.unmodifiableSet(Set)
of Sentinels.- Specified by:
getSentinels
in interfaceRedisConfiguration.SentinelConfiguration
- Returns:
Set
of sentinels. Never null.
-
addSentinel
Add sentinel.- Parameters:
sentinel
- must not be null.
-
setMaster
Description copied from interface:RedisConfiguration.SentinelConfiguration
Set the master node.- Specified by:
setMaster
in interfaceRedisConfiguration.SentinelConfiguration
- Parameters:
master
- must not be null.
-
getMaster
Description copied from interface:RedisConfiguration.SentinelConfiguration
Get the Sentinel master node.- Specified by:
getMaster
in interfaceRedisConfiguration.SentinelConfiguration
- Returns:
- get the master node or null if not set.
-
master
- Parameters:
master
- The master node name.- Returns:
- this.
- See Also:
-
master
- Parameters:
master
- the master node- Returns:
- this.
- See Also:
-
sentinel
- Parameters:
sentinel
- the node to add as sentinel.- Returns:
- this.
- See Also:
-
sentinel
- Parameters:
host
- redis sentinel node host name or ip.port
- redis sentinel port.- Returns:
- this.
- See Also:
-
getDatabase
public int getDatabase()Description copied from interface:RedisConfiguration.WithDatabaseIndex
Get the database index to use.- Specified by:
getDatabase
in interfaceRedisConfiguration.WithDatabaseIndex
- Returns:
zero
by default.
-
setDatabase
public void setDatabase(int index) Description copied from interface:RedisConfiguration.WithDatabaseIndex
Set the database index to use.- Specified by:
setDatabase
in interfaceRedisConfiguration.WithDatabaseIndex
-
setUsername
Description copied from interface:RedisConfiguration.WithAuthentication
Create and set a username with the givenString
. Requires Redis 6 or newer.- Specified by:
setUsername
in interfaceRedisConfiguration.WithAuthentication
- Parameters:
username
- the username.
-
getUsername
Description copied from interface:RedisConfiguration.WithAuthentication
Get the username to use when connecting.- Specified by:
getUsername
in interfaceRedisConfiguration.WithAuthentication
- Returns:
- null if none set.
-
getPassword
Description copied from interface:RedisConfiguration.WithAuthentication
Get the RedisPassword to use when connecting.- Specified by:
getPassword
in interfaceRedisConfiguration.WithAuthentication
- Returns:
RedisPassword.none()
if none set.
-
setPassword
Description copied from interface:RedisConfiguration.WithAuthentication
Create and set aRedisPassword
for givenString
.- Specified by:
setPassword
in interfaceRedisConfiguration.WithAuthentication
- Parameters:
password
- must not be null useRedisPassword.none()
instead.
-
getSentinelUsername
Description copied from interface:RedisConfiguration.SentinelConfiguration
Get the username to use when connecting.- Specified by:
getSentinelUsername
in interfaceRedisConfiguration.SentinelConfiguration
- Returns:
- null if none set.
-
setSentinelUsername
Description copied from interface:RedisConfiguration.SentinelConfiguration
Create and set a username with the givenString
. Requires Redis 6 or newer.- Specified by:
setSentinelUsername
in interfaceRedisConfiguration.SentinelConfiguration
- Parameters:
sentinelUsername
- the username for sentinel.
-
setSentinelPassword
Description copied from interface:RedisConfiguration.SentinelConfiguration
Set aRedisPassword
to be used when authenticating with Redis Sentinel.- Specified by:
setSentinelPassword
in interfaceRedisConfiguration.SentinelConfiguration
- Parameters:
sentinelPassword
- must not be null useRedisPassword.none()
instead.
-
getSentinelPassword
Description copied from interface:RedisConfiguration.SentinelConfiguration
Returns theRedisPassword
to use when connecting to a Redis Sentinel.
Can be set viaRedisConfiguration.SentinelConfiguration.setSentinelPassword(RedisPassword)
orRedisPassword.none()
if no password has been set.- Specified by:
getSentinelPassword
in interfaceRedisConfiguration.SentinelConfiguration
- Returns:
- the
RedisPassword
for authenticating with Redis Sentinel.
-
equals
-
hashCode
public int hashCode()
-
of(PropertySource)
instead.