-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLUSTER SHARDS command support (#3598)
* Add CLUSTER SHARDS command (#2984) * Added new classes for CLUSTER SHARDS response * Slots type changed to List<List<Long>> + style fixed * Apply suggestions from code review * reset redis before ClusterCommandTest added * isSsl() added to ClusterShardNodeInfo * Several assertion added to clusterShards test --------- Co-authored-by: Khokhlov Aleksey <[email protected]> Co-authored-by: M Sazzadul Hoque <[email protected]>
- Loading branch information
1 parent
701df24
commit 452ea52
Showing
7 changed files
with
314 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/redis/clients/jedis/resps/ClusterShardInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package redis.clients.jedis.resps; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* This class holds information about a shard of the cluster with command {@code CLUSTER SHARDS}. | ||
* They can be accessed via getters. There is also {@link ClusterShardInfo#getClusterShardInfo()} | ||
* method that returns a generic {@link Map} in case more info are returned from the server. | ||
*/ | ||
public class ClusterShardInfo { | ||
|
||
public static final String SLOTS = "slots"; | ||
public static final String NODES = "nodes"; | ||
|
||
private final List<List<Long>> slots; | ||
private final List<ClusterShardNodeInfo> nodes; | ||
|
||
private final Map<String, Object> clusterShardInfo; | ||
|
||
/** | ||
* @param map contains key-value pairs with cluster shard info | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public ClusterShardInfo(Map<String, Object> map) { | ||
slots = (List<List<Long>>) map.get(SLOTS); | ||
nodes = (List<ClusterShardNodeInfo>) map.get(NODES); | ||
|
||
clusterShardInfo = map; | ||
} | ||
|
||
public List<List<Long>> getSlots() { | ||
return slots; | ||
} | ||
|
||
public List<ClusterShardNodeInfo> getNodes() { | ||
return nodes; | ||
} | ||
|
||
public Map<String, Object> getClusterShardInfo() { | ||
return clusterShardInfo; | ||
} | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
src/main/java/redis/clients/jedis/resps/ClusterShardNodeInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package redis.clients.jedis.resps; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* This class holds information about a node of the cluster with command {@code CLUSTER SHARDS}. | ||
* They can be accessed via getters. There is also {@link ClusterShardNodeInfo#getClusterShardNodeInfo()} | ||
* method that returns a generic {@link Map} in case more info are returned from the server. | ||
*/ | ||
public class ClusterShardNodeInfo { | ||
|
||
public static final String ID = "id"; | ||
public static final String ENDPOINT = "endpoint"; | ||
public static final String IP = "ip"; | ||
public static final String HOSTNAME = "hostname"; | ||
public static final String PORT = "port"; | ||
public static final String TLS_PORT = "tls-port"; | ||
public static final String ROLE = "role"; | ||
public static final String REPLICATION_OFFSET = "replication-offset"; | ||
public static final String HEALTH = "health"; | ||
|
||
private final String id; | ||
private final String endpoint; | ||
private final String ip; | ||
private final String hostname; | ||
private final Long port; | ||
private final Long tlsPort; | ||
private final String role; | ||
private final Long replicationOffset; | ||
private final String health; | ||
|
||
private final Map<String, Object> clusterShardNodeInfo; | ||
|
||
/** | ||
* @param map contains key-value pairs with node info | ||
*/ | ||
public ClusterShardNodeInfo(Map<String, Object> map) { | ||
id = (String) map.get(ID); | ||
endpoint = (String) map.get(ENDPOINT); | ||
ip = (String) map.get(IP); | ||
hostname = (String) map.get(HOSTNAME); | ||
port = (Long) map.get(PORT); | ||
tlsPort = (Long) map.get(TLS_PORT); | ||
role = (String) map.get(ROLE); | ||
replicationOffset = (Long) map.get(REPLICATION_OFFSET); | ||
health = (String) map.get(HEALTH); | ||
|
||
clusterShardNodeInfo = map; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getEndpoint() { | ||
return endpoint; | ||
} | ||
|
||
public String getIp() { | ||
return ip; | ||
} | ||
|
||
public String getHostname() { | ||
return hostname; | ||
} | ||
|
||
public Long getPort() { | ||
return port; | ||
} | ||
|
||
public Long getTlsPort() { | ||
return tlsPort; | ||
} | ||
|
||
public String getRole() { | ||
return role; | ||
} | ||
|
||
public Long getReplicationOffset() { | ||
return replicationOffset; | ||
} | ||
|
||
public String getHealth() { | ||
return health; | ||
} | ||
|
||
public Map<String, Object> getClusterShardNodeInfo() { | ||
return clusterShardNodeInfo; | ||
} | ||
|
||
public boolean isSsl() { | ||
return tlsPort != null; | ||
} | ||
} |
Oops, something went wrong.