refactoring

pull/3960/head
Nikita Koksharov 3 years ago
parent 83663fb52e
commit e7f7a4ec2c

@ -463,7 +463,9 @@ public interface RedisCommands {
RedisStrictCommand<Void> SENTINEL_MONITOR = new RedisStrictCommand<Void>("SENTINEL", "MONITOR", new VoidReplayConvertor());
RedisStrictCommand<RedisURI> SENTINEL_GET_MASTER_ADDR_BY_NAME = new RedisStrictCommand<>("SENTINEL", "GET-MASTER-ADDR-BY-NAME",
new RedisURIDecoder());
new RedisURIDecoder(false));
RedisStrictCommand<RedisURI> SENTINEL_GET_MASTER_ADDR_BY_NAME_SSL = new RedisStrictCommand<>("SENTINEL", "GET-MASTER-ADDR-BY-NAME",
new RedisURIDecoder(true));
RedisCommand<List<Map<String, String>>> SENTINEL_MASTERS = new RedisCommand<List<Map<String, String>>>("SENTINEL", "MASTERS",
new ListMultiDecoder2(new ListResultReplayDecoder(), new ObjectMapReplayDecoder()));
RedisCommand<Map<String, String>> SENTINEL_MASTER = new RedisCommand("SENTINEL", "MASTER", new ObjectMapReplayDecoder());

@ -30,6 +30,17 @@ import java.util.List;
*/
public class RedisURIDecoder implements MultiDecoder<RedisURI> {
private final String scheme;
public RedisURIDecoder(boolean ssl) {
super();
if (ssl) {
scheme = "rediss";
} else {
scheme = "redis";
}
}
@Override
public Decoder<Object> getDecoder(Codec codec, int paramNum, State state) {
return StringCodec.INSTANCE.getValueDecoder();
@ -40,7 +51,7 @@ public class RedisURIDecoder implements MultiDecoder<RedisURI> {
if (parts.isEmpty()) {
return null;
}
return new RedisURI("redis", (String) parts.get(0), Integer.valueOf((String) parts.get(1)));
return new RedisURI(scheme, (String) parts.get(0), Integer.valueOf((String) parts.get(1)));
}
}

@ -698,9 +698,6 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
protected RFuture<RedisURI> resolveIP(String scheme, RedisURI address) {
if (address.isIP()) {
RedisURI addr = applyNatMap(address);
if (!scheme.equals(addr.getScheme())) {
addr = new RedisURI(scheme, addr.getHost(), addr.getPort());
}
return RedissonPromise.newSucceededFuture(addr);
}

@ -27,6 +27,7 @@ import org.redisson.api.RFuture;
import org.redisson.client.*;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.RedisStrictCommand;
import org.redisson.config.*;
import org.redisson.connection.ClientConnectionsEntry.FreezeReason;
import org.redisson.misc.AsyncCountDownLatch;
@ -65,6 +66,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
private AddressResolver<InetSocketAddress> sentinelResolver;
private final NatMapper natMapper;
private final RedisStrictCommand<RedisURI> masterHostCommand;
private final String sentinelPassword;
private boolean usePassword = false;
@ -103,6 +105,12 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
checkAuth(cfg);
if ("redis".equals(scheme)) {
masterHostCommand = RedisCommands.SENTINEL_GET_MASTER_ADDR_BY_NAME;
} else {
masterHostCommand = RedisCommands.SENTINEL_GET_MASTER_ADDR_BY_NAME_SSL;
}
Throwable lastException = null;
for (String address : cfg.getSentinelAddresses()) {
RedisURI addr = new RedisURI(address);
@ -120,7 +128,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
continue;
}
RedisURI master = connection.sync(RedisCommands.SENTINEL_GET_MASTER_ADDR_BY_NAME, cfg.getMasterName());
RedisURI master = connection.sync(masterHostCommand, cfg.getMasterName());
if (master == null) {
throw new RedisConnectionException("Master node is undefined! SENTINEL GET-MASTER-ADDR-BY-NAME command returns empty result!");
}
@ -507,7 +515,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
}
private RFuture<RedisURI> checkMasterChange(SentinelServersConfig cfg, RedisConnection connection) {
RFuture<RedisURI> masterFuture = connection.async(StringCodec.INSTANCE, RedisCommands.SENTINEL_GET_MASTER_ADDR_BY_NAME, cfg.getMasterName());
RFuture<RedisURI> masterFuture = connection.async(StringCodec.INSTANCE, masterHostCommand, cfg.getMasterName());
masterFuture.thenCompose(u -> resolveIP(scheme, u))
.whenComplete((newMaster, e) -> {
if (e != null) {

Loading…
Cancel
Save