Merge pull request #3097 from ghollies/sentinel-password

Configure Sentinel Password
pull/3332/head^2
Nikita Koksharov 4 years ago committed by GitHub
commit cbdaaaae4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -37,6 +37,8 @@ public class SentinelServersConfig extends BaseMasterSlaveServersConfig<Sentinel
private String masterName;
private String sentinelPassword;
/**
* Database index used for Redis connection
*/
@ -60,6 +62,7 @@ public class SentinelServersConfig extends BaseMasterSlaveServersConfig<Sentinel
setScanInterval(config.getScanInterval());
setNatMapper(config.getNatMapper());
setCheckSentinelsList(config.isCheckSentinelsList());
setSentinelPassword(config.getSentinelPassword());
}
/**
@ -76,6 +79,21 @@ public class SentinelServersConfig extends BaseMasterSlaveServersConfig<Sentinel
return masterName;
}
/**
* Password required by the Redis Sentinel servers for authentication.
*
* @param sentinelPassword of Redis
* @return config
*/
public SentinelServersConfig setSentinelPassword(String sentinelPassword) {
this.sentinelPassword = sentinelPassword;
return this;
}
public String getSentinelPassword() {
return sentinelPassword;
}
/**
* Add Redis Sentinel node address in host:port format. Multiple nodes at once could be added.
*

@ -62,9 +62,10 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
private final Set<RedisURI> disconnectedSlaves = new HashSet<>();
private ScheduledFuture<?> monitorFuture;
private AddressResolver<InetSocketAddress> sentinelResolver;
private final NatMapper natMapper;
private final String sentinelPassword;
private boolean usePassword = false;
private String scheme;
@ -79,6 +80,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
}
this.config = create(cfg);
this.sentinelPassword = cfg.getSentinelPassword();
initTimer(this.config);
this.natMapper = cfg.getNatMapper();
@ -252,7 +254,13 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
String sslHostname) {
RedisClientConfig result = super.createRedisConfig(type, address, timeout, commandTimeout, sslHostname);
if (type == NodeType.SENTINEL && !usePassword) {
result.setUsername(null);
result.setPassword(null);
} else if (type == NodeType.SENTINEL && usePassword) {
result.setUsername(null);
if (sentinelPassword != null) {
result.setPassword(sentinelPassword);
}
}
return result;
}

Loading…
Cancel
Save