Feature - support of "valkey" and "valkeys" schemes in urls #6301

pull/6384/head
Nikita Koksharov 3 weeks ago
parent fd131ce1a3
commit 2940a7acd4

@ -740,10 +740,9 @@ public interface RedisCommands {
Set<String> SCAN_COMMANDS = new HashSet<String>(
Arrays.asList(HSCAN.getName(), SCAN.getName(), ZSCAN.getName(), SSCAN.getName()));
RedisStrictCommand<List<ClusterNodeInfo>> CLUSTER_NODES = new RedisStrictCommand<List<ClusterNodeInfo>>("CLUSTER", "NODES",
RedisStrictCommand<List<ClusterNodeInfo>> REDIS_CLUSTER_NODES = new RedisStrictCommand<List<ClusterNodeInfo>>("CLUSTER", "NODES",
new ObjectDecoder(new ClusterNodesDecoder(RedisURI.REDIS_PROTOCOL)));
RedisStrictCommand<List<ClusterNodeInfo>> CLUSTER_NODES_SSL = new RedisStrictCommand<List<ClusterNodeInfo>>("CLUSTER", "NODES",
new ObjectDecoder(new ClusterNodesDecoder(RedisURI.REDIS_SSL_PROTOCOL)));
RedisStrictCommand<Long> TIME_LONG = new RedisStrictCommand<Long>("TIME", new TimeLongObjectDecoder());
RedisStrictCommand<Time> TIME = new RedisStrictCommand<Time>("TIME", new TimeObjectDecoder());
RedisStrictCommand<Map<String, String>> CLUSTER_INFO = new RedisStrictCommand<Map<String, String>>("CLUSTER", "INFO", new StringMapDataDecoder());

@ -34,11 +34,11 @@ import java.util.List;
*/
public class ClusterNodesDecoder implements Decoder<List<ClusterNodeInfo>> {
private final String protocol;
private final String scheme;
public ClusterNodesDecoder(String protocol) {
public ClusterNodesDecoder(String scheme) {
super();
this.protocol = protocol;
this.scheme = scheme;
}
@Override
@ -109,7 +109,7 @@ public class ClusterNodesDecoder implements Decoder<List<ClusterNodeInfo>> {
String port = addr.substring(name.length() + 1);
addr = parts[1] + ":" + port;
}
return protocol + addr;
return scheme + "://" + addr;
}
}

@ -23,6 +23,8 @@ 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.client.protocol.decoder.ClusterNodesDecoder;
import org.redisson.client.protocol.decoder.ObjectDecoder;
import org.redisson.cluster.ClusterNodeInfo;
import org.redisson.cluster.ClusterNodeInfo.Flag;
import org.redisson.cluster.ClusterPartition;
@ -102,10 +104,8 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
configEndpointHostName = addr.getHost();
}
clusterNodesCommand = RedisCommands.CLUSTER_NODES;
if (addr.isSsl()) {
clusterNodesCommand = RedisCommands.CLUSTER_NODES_SSL;
}
clusterNodesCommand = new RedisStrictCommand<List<ClusterNodeInfo>>("CLUSTER", "NODES",
new ObjectDecoder(new ClusterNodesDecoder(addr.getScheme())));
if (!skipShardingDetection) {
if (cfg.getShardedSubscriptionMode() == ShardedSubscriptionMode.AUTO) {

@ -34,8 +34,10 @@ public final class RedisURI {
public static final String REDIS_PROTOCOL= "redis://";
public static final String REDIS_SSL_PROTOCOL = "rediss://";
public static final String VALKEY_PROTOCOL= "valkey://";
public static final String VALKEY_SSL_PROTOCOL = "valkeys://";
private final boolean ssl;
private final String scheme;
private final String host;
private final int port;
private String username;
@ -43,14 +45,17 @@ public final class RedisURI {
private int hashCode;
public static boolean isValid(String url) {
return url.startsWith(REDIS_PROTOCOL) || url.startsWith(REDIS_SSL_PROTOCOL);
return url.startsWith(REDIS_PROTOCOL)
|| url.startsWith(REDIS_SSL_PROTOCOL)
|| url.startsWith(VALKEY_PROTOCOL)
|| url.startsWith(VALKEY_SSL_PROTOCOL);
}
public RedisURI(String scheme, String host, int port) {
this.ssl = "rediss".equals(scheme);
this.scheme = scheme;
this.host = host;
this.port = port;
this.hashCode = Objects.hash(ssl, host, port);
this.hashCode = Objects.hash(isSsl(), host, port);
}
public RedisURI(String uri) {
@ -81,7 +86,7 @@ public final class RedisURI {
host = url.getHost();
port = url.getPort();
ssl = uri.startsWith("rediss://");
scheme = uri.split("://")[0];
} catch (MalformedURLException | UnsupportedEncodingException e) {
throw new IllegalArgumentException(e);
}
@ -101,10 +106,7 @@ public final class RedisURI {
}
public String getScheme() {
if (ssl) {
return "rediss";
}
return "redis";
return scheme;
}
public String getUsername() {
@ -116,7 +118,7 @@ public final class RedisURI {
}
public boolean isSsl() {
return ssl;
return "rediss".equals(scheme) || "valkeys".equals(scheme);
}
public String getHost() {
@ -153,7 +155,7 @@ public final class RedisURI {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RedisURI redisURI = (RedisURI) o;
return ssl == redisURI.ssl && port == redisURI.port && Objects.equals(host, redisURI.host);
return isSsl() == redisURI.isSsl() && port == redisURI.port && Objects.equals(host, redisURI.host);
}
@Override

@ -91,7 +91,7 @@ public class RedissonBatchTest extends RedisDockerTest {
cfg.setAddress(config.useClusterServers().getNodeAddresses().get(0));
RedisClient c = RedisClient.create(cfg);
RedisConnection cc = c.connect();
List<ClusterNodeInfo> mastersList = cc.sync(RedisCommands.CLUSTER_NODES);
List<ClusterNodeInfo> mastersList = cc.sync(RedisCommands.REDIS_CLUSTER_NODES);
mastersList = mastersList.stream().filter(i -> i.containsFlag(ClusterNodeInfo.Flag.MASTER)).collect(Collectors.toList());
c.shutdown();

@ -495,7 +495,7 @@ public class RedissonTopicTest extends RedisDockerTest {
cfg.setAddress(client.getConfig().useClusterServers().getNodeAddresses().get(0));
RedisClient c = RedisClient.create(cfg);
RedisConnection cc = c.connect();
List<ClusterNodeInfo> mastersList = cc.sync(RedisCommands.CLUSTER_NODES);
List<ClusterNodeInfo> mastersList = cc.sync(RedisCommands.REDIS_CLUSTER_NODES);
mastersList = mastersList.stream().filter(i -> i.containsFlag(ClusterNodeInfo.Flag.MASTER)).collect(Collectors.toList());
c.shutdown();

Loading…
Cancel
Save