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 for setting up
RedisConnection via RedisConnectionFactory using connecting
to Redis Sentinel(s). Useful when setting up a high availability Redis
environment.- Since:
- 1.4
- Author:
- Christoph Strobl, Thomas Darimont, Mark Paluch, Vikas Garg
-
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
ConstructorsConstructorDescriptionCreates newRedisSentinelConfiguration.RedisSentinelConfiguration(String master, Set<String> sentinelHostAndPorts) CreatesRedisSentinelConfigurationfor given hostPort combinations.RedisSentinelConfiguration(org.springframework.core.env.PropertySource<?> propertySource) CreatesRedisSentinelConfigurationlooking up values in givenPropertySource. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSentinel(RedisNode sentinel) Add sentinel.booleanintGet the database index to use.Get the Sentinel master node.Get the RedisPassword to use when connecting.Returns theRedisPasswordto 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.inthashCode()voidsetDatabase(int index) Set the database index to use.voidSet the master node.voidsetPassword(RedisPassword password) Create and set aRedisPasswordfor givenString.voidsetSentinelPassword(RedisPassword sentinelPassword) Set aRedisPasswordto be used when authenticating with Redis Sentinel.voidsetSentinels(Iterable<RedisNode> sentinels) Set Sentinels to connect to.voidsetSentinelUsername(String sentinelUsername) Create and set a username with the givenString.voidsetUsername(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, waitMethods inherited from interface org.springframework.data.redis.connection.RedisConfiguration
getDatabaseOrElse, getPasswordOrElseMethods inherited from interface org.springframework.data.redis.connection.RedisConfiguration.SentinelConfiguration
getDataNodePassword, getDataNodeUsername, setMaster, setSentinelPassword, setSentinelPasswordMethods inherited from interface org.springframework.data.redis.connection.RedisConfiguration.WithAuthentication
setPassword, setPassword
-
Constructor Details
-
RedisSentinelConfiguration
public RedisSentinelConfiguration()Creates newRedisSentinelConfiguration. -
RedisSentinelConfiguration
CreatesRedisSentinelConfigurationfor given hostPort 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
public RedisSentinelConfiguration(org.springframework.core.env.PropertySource<?> propertySource) CreatesRedisSentinelConfigurationlooking up values in 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
-
setSentinels
Set Sentinels to connect to.- Parameters:
sentinels- must not be null.
-
getSentinels
Description copied from interface:RedisConfiguration.SentinelConfigurationReturns anCollections.unmodifiableSet(Set)of Sentinels.- Specified by:
getSentinelsin interfaceRedisConfiguration.SentinelConfiguration- Returns:
Setof sentinels. Never null.
-
addSentinel
Add sentinel.- Parameters:
sentinel- must not be null.
-
setMaster
Description copied from interface:RedisConfiguration.SentinelConfigurationSet the master node.- Specified by:
setMasterin interfaceRedisConfiguration.SentinelConfiguration- Parameters:
master- must not be null.
-
getMaster
Description copied from interface:RedisConfiguration.SentinelConfigurationGet the Sentinel master node.- Specified by:
getMasterin 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.WithDatabaseIndexGet the database index to use.- Specified by:
getDatabasein interfaceRedisConfiguration.WithDatabaseIndex- Returns:
zeroby default.
-
setDatabase
public void setDatabase(int index) Description copied from interface:RedisConfiguration.WithDatabaseIndexSet the database index to use.- Specified by:
setDatabasein interfaceRedisConfiguration.WithDatabaseIndex
-
setUsername
Description copied from interface:RedisConfiguration.WithAuthenticationCreate and set a username with the givenString. Requires Redis 6 or newer.- Specified by:
setUsernamein interfaceRedisConfiguration.WithAuthentication- Parameters:
username- the username.
-
getUsername
Description copied from interface:RedisConfiguration.WithAuthenticationGet the username to use when connecting.- Specified by:
getUsernamein interfaceRedisConfiguration.WithAuthentication- Returns:
- null if none set.
-
getPassword
Description copied from interface:RedisConfiguration.WithAuthenticationGet the RedisPassword to use when connecting.- Specified by:
getPasswordin interfaceRedisConfiguration.WithAuthentication- Returns:
RedisPassword.none()if none set.
-
setPassword
Description copied from interface:RedisConfiguration.WithAuthenticationCreate and set aRedisPasswordfor givenString.- Specified by:
setPasswordin interfaceRedisConfiguration.WithAuthentication- Parameters:
password- must not be null useRedisPassword.none()instead.
-
getSentinelUsername
Description copied from interface:RedisConfiguration.SentinelConfigurationGet the username to use when connecting.- Specified by:
getSentinelUsernamein interfaceRedisConfiguration.SentinelConfiguration- Returns:
- null if none set.
-
setSentinelUsername
Description copied from interface:RedisConfiguration.SentinelConfigurationCreate and set a username with the givenString. Requires Redis 6 or newer.- Specified by:
setSentinelUsernamein interfaceRedisConfiguration.SentinelConfiguration- Parameters:
sentinelUsername- the username for sentinel.
-
setSentinelPassword
Description copied from interface:RedisConfiguration.SentinelConfigurationSet aRedisPasswordto be used when authenticating with Redis Sentinel.- Specified by:
setSentinelPasswordin interfaceRedisConfiguration.SentinelConfiguration- Parameters:
sentinelPassword- must not be null useRedisPassword.none()instead.
-
getSentinelPassword
Description copied from interface:RedisConfiguration.SentinelConfigurationReturns theRedisPasswordto use when connecting to a Redis Sentinel.
Can be set viaRedisConfiguration.SentinelConfiguration.setSentinelPassword(RedisPassword)orRedisPassword.none()if no password has been set.- Specified by:
getSentinelPasswordin interfaceRedisConfiguration.SentinelConfiguration- Returns:
- the
RedisPasswordfor authenticating with Redis Sentinel.
-
equals
-
hashCode
public int hashCode()
-