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 to set up a
RedisConnection
via RedisConnectionFactory
for connecting to
Redis Cluster. Useful when setting up a highly available Redis
environment.- Since:
- 1.7
- Author:
- Christoph Strobl, Mark Paluch, John Blum
-
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, defaultRedisClusterConfiguration
.RedisClusterConfiguration
(Collection<String> clusterNodes) Creates a newRedisClusterConfiguration
for givenhostPort
combinations.RedisClusterConfiguration
(PropertySource<?> propertySource) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addClusterNode
(RedisNode node) Add a cluster node to configuration.clusterNode
(String host, Integer port) clusterNode
(RedisNode node) boolean
Returns anSet
ofcluster nodes
.Get the RedisPassword to use when connecting.Get the username to use when connecting.int
hashCode()
static RedisClusterConfiguration
of
(PropertySource<?> propertySource) Creates a newRedisClusterConfiguration
looking up configuration values from the givenPropertySource
.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 a new, defaultRedisClusterConfiguration
. -
RedisClusterConfiguration
Creates a newRedisClusterConfiguration
for givenhostPort
combinations.clusterHostAndPorts[0] = 127.0.0.1:23679 clusterHostAndPorts[1] = 127.0.0.1:23680 ...
- Parameters:
clusterNodes
- must not be null.
-
RedisClusterConfiguration
Deprecated.since 3.3, useRedisSentinelConfiguration.of(PropertySource)
instead. This constructor will be made private in the next major release.Creates a newRedisClusterConfiguration
looking up configuration values from the 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
-
of
Creates a newRedisClusterConfiguration
looking up configuration values from the 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.- Returns:
- a new
RedisClusterConfiguration
configured from the givenPropertySource
. - Since:
- 3.3
-
setClusterNodes
Set cluster nodes to connect to.- Parameters:
nodes
- must not be null.
-
getClusterNodes
Description copied from interface:RedisConfiguration.ClusterConfiguration
Returns anSet
ofcluster nodes
.- Specified by:
getClusterNodes
in interfaceRedisConfiguration.ClusterConfiguration
- Returns:
Set
ofcluster nodes
. Never null.
-
addClusterNode
Add a cluster node to configuration.- Parameters:
node
- must not be null.
-
clusterNode
- Parameters:
host
- Redis cluster node host name or ip address.port
- Redis cluster node port.- Returns:
- this.
-
clusterNode
- Returns:
- this.
-
setMaxRedirects
public void setMaxRedirects(int maxRedirects) - Parameters:
maxRedirects
- the max number of redirects to follow.
-
getMaxRedirects
- Specified by:
getMaxRedirects
in interfaceRedisConfiguration.ClusterConfiguration
- Returns:
- max number of redirects to follow or null if not set.
-
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.
-
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.
-
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.
-
equals
-
hashCode
public int hashCode()
-
RedisSentinelConfiguration.of(PropertySource)
instead.