Class RedisClusterConfiguration
java.lang.Object
org.springframework.data.redis.connection.RedisClusterConfiguration
- All Implemented Interfaces:
RedisConfiguration
,RedisConfiguration.ClusterConfiguration
,RedisConfiguration.WithAuthentication
,RedisConfiguration.WithPassword
public class RedisClusterConfiguration
extends Object
implements RedisConfiguration, RedisConfiguration.ClusterConfiguration
Configuration class used for setting up
RedisConnection
via RedisConnectionFactory
using connecting
to Redis Cluster. Useful when setting up a high availability Redis
environment.- Since:
- 1.7
- Author:
- Christoph Strobl, Mark Paluch
-
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 newRedisClusterConfiguration
.RedisClusterConfiguration
(Collection<String> clusterNodes) CreatesRedisClusterConfiguration
for given hostPort combinations.RedisClusterConfiguration
(org.springframework.core.env.PropertySource<?> propertySource) CreatesRedisClusterConfiguration
looking up values in givenPropertySource
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addClusterNode
(RedisNode node) Add a cluster node to configuration.clusterNode
(String host, Integer port) clusterNode
(RedisNode node) boolean
Returns anCollections.unmodifiableSet(Set)
of cluster nodes.Get the RedisPassword to use when connecting.Get the username to use when connecting.int
hashCode()
void
setClusterNodes
(Iterable<RedisNode> nodes) Set cluster nodes to connect to.void
setMaxRedirects
(int maxRedirects) void
setPassword
(RedisPassword password) Create and set aRedisPassword
for 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.WithAuthentication
setPassword, setPassword
-
Constructor Details
-
RedisClusterConfiguration
public RedisClusterConfiguration()Creates newRedisClusterConfiguration
. -
RedisClusterConfiguration
CreatesRedisClusterConfiguration
for given hostPort combinations.clusterHostAndPorts[0] = 127.0.0.1:23679 clusterHostAndPorts[1] = 127.0.0.1:23680 ...
- Parameters:
clusterNodes
- must not be null.
-
RedisClusterConfiguration
public RedisClusterConfiguration(org.springframework.core.env.PropertySource<?> propertySource) CreatesRedisClusterConfiguration
looking up values in givenPropertySource
.spring.redis.cluster.nodes=127.0.0.1:23679,127.0.0.1:23680,127.0.0.1:23681 spring.redis.cluster.max-redirects=3
- Parameters:
propertySource
- must not be null.
-
-
Method Details
-
setClusterNodes
Set cluster nodes to connect to.- Parameters:
nodes
- must not be null.
-
getClusterNodes
Description copied from interface:RedisConfiguration.ClusterConfiguration
Returns anCollections.unmodifiableSet(Set)
of cluster nodes.- Specified by:
getClusterNodes
in interfaceRedisConfiguration.ClusterConfiguration
- Returns:
Set
of nodes. Never null.
-
addClusterNode
Add a cluster node to configuration.- Parameters:
node
- must not be null.
-
clusterNode
- Returns:
- this.
-
getMaxRedirects
- Specified by:
getMaxRedirects
in interfaceRedisConfiguration.ClusterConfiguration
- Returns:
- max number of redirects to follow or null if not set.
-
setMaxRedirects
public void setMaxRedirects(int maxRedirects) - Parameters:
maxRedirects
- the max number of redirects to follow.
-
clusterNode
- Parameters:
host
- Redis cluster node host name or ip address.port
- Redis cluster node port.- Returns:
- this.
-
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.
-
equals
-
hashCode
public int hashCode()
-