Skip to content

Commit

Permalink
Merge branch 'master' into netty-01
Browse files Browse the repository at this point in the history
  • Loading branch information
chayim committed Nov 14, 2023
2 parents c5d42b1 + 452ea52 commit 63e0f5c
Show file tree
Hide file tree
Showing 13 changed files with 368 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/release-drafter-config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name-template: '$NEXT_MINOR_VERSION'
tag-template: 'v$NEXT_MINOR_VERSION'
filter-by-commitish: true
commitish: master
autolabeler:
- label: 'maintenance'
files:
Expand Down Expand Up @@ -35,6 +37,8 @@ categories:
labels:
- 'maintenance'
- 'dependencies'
- 'documentation'
- 'docs'
- 'testing'
change-template: '- $TITLE (#$NUMBER)'
exclude-labels:
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.2</version>
<configuration>
<systemPropertyVariables>
<redis-hosts>${redis-hosts}</redis-hosts>
Expand Down Expand Up @@ -226,7 +226,7 @@
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.0</version>
<version>3.6.2</version>
<configuration>
<source>8</source><!-- Until JDK 11+ -->
<detectJavaApiLink>false</detectJavaApiLink><!-- Until JDK 11+ -->
Expand Down Expand Up @@ -327,7 +327,7 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.2</version>
<configuration>
<test>**/examples/*Example.java</test>
</configuration>
Expand Down
102 changes: 102 additions & 0 deletions src/main/java/redis/clients/jedis/BuilderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,108 @@ public Map<String, CommandInfo> build(Object data) {
}
};

private static final Builder<List<List<Long>>> CLUSTER_SHARD_SLOTS_RANGES = new Builder<List<List<Long>>>() {

@Override
public List<List<Long>> build(Object data) {
if (null == data) {
return null;
}

List<Long> rawSlots = (List<Long>) data;
List<List<Long>> slotsRanges = new ArrayList<>();
for (int i = 0; i < rawSlots.size(); i += 2) {
slotsRanges.add(Arrays.asList(rawSlots.get(i), rawSlots.get(i + 1)));
}
return slotsRanges;
}
};

private static final Builder<List<ClusterShardNodeInfo>> CLUSTER_SHARD_NODE_INFO_LIST
= new Builder<List<ClusterShardNodeInfo>>() {

final Map<String, Builder> mappingFunctions = createDecoderMap();

private Map<String, Builder> createDecoderMap() {

Map<String, Builder> tempMappingFunctions = new HashMap<>();
tempMappingFunctions.put(ClusterShardNodeInfo.ID, STRING);
tempMappingFunctions.put(ClusterShardNodeInfo.ENDPOINT, STRING);
tempMappingFunctions.put(ClusterShardNodeInfo.IP, STRING);
tempMappingFunctions.put(ClusterShardNodeInfo.HOSTNAME, STRING);
tempMappingFunctions.put(ClusterShardNodeInfo.PORT, LONG);
tempMappingFunctions.put(ClusterShardNodeInfo.TLS_PORT, LONG);
tempMappingFunctions.put(ClusterShardNodeInfo.ROLE, STRING);
tempMappingFunctions.put(ClusterShardNodeInfo.REPLICATION_OFFSET, LONG);
tempMappingFunctions.put(ClusterShardNodeInfo.HEALTH, STRING);

return tempMappingFunctions;
}

@Override
@SuppressWarnings("unchecked")
public List<ClusterShardNodeInfo> build(Object data) {
if (null == data) {
return null;
}

List<ClusterShardNodeInfo> response = new ArrayList<>();

List<Object> clusterShardNodeInfos = (List<Object>) data;
for (Object clusterShardNodeInfoObject : clusterShardNodeInfos) {
List<Object> clusterShardNodeInfo = (List<Object>) clusterShardNodeInfoObject;
Iterator<Object> iterator = clusterShardNodeInfo.iterator();
response.add(new ClusterShardNodeInfo(createMapFromDecodingFunctions(iterator, mappingFunctions)));
}

return response;
}

@Override
public String toString() {
return "List<ClusterShardNodeInfo>";
}
};

public static final Builder<List<ClusterShardInfo>> CLUSTER_SHARD_INFO_LIST
= new Builder<List<ClusterShardInfo>>() {

final Map<String, Builder> mappingFunctions = createDecoderMap();

private Map<String, Builder> createDecoderMap() {

Map<String, Builder> tempMappingFunctions = new HashMap<>();
tempMappingFunctions.put(ClusterShardInfo.SLOTS, CLUSTER_SHARD_SLOTS_RANGES);
tempMappingFunctions.put(ClusterShardInfo.NODES, CLUSTER_SHARD_NODE_INFO_LIST);

return tempMappingFunctions;
}

@Override
@SuppressWarnings("unchecked")
public List<ClusterShardInfo> build(Object data) {
if (null == data) {
return null;
}

List<ClusterShardInfo> response = new ArrayList<>();

List<Object> clusterShardInfos = (List<Object>) data;
for (Object clusterShardInfoObject : clusterShardInfos) {
List<Object> clusterShardInfo = (List<Object>) clusterShardInfoObject;
Iterator<Object> iterator = clusterShardInfo.iterator();
response.add(new ClusterShardInfo(createMapFromDecodingFunctions(iterator, mappingFunctions)));
}

return response;
}

@Override
public String toString() {
return "List<ClusterShardInfo>";
}
};

public static final Builder<List<Module>> MODULE_LIST = new Builder<List<Module>>() {
@Override
public List<Module> build(Object data) {
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/redis/clients/jedis/CommandArguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import redis.clients.jedis.args.Rawable;
import redis.clients.jedis.args.RawableFactory;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.params.IParams;
import redis.clients.jedis.search.RediSearchUtil;

public class CommandArguments implements Iterable<Rawable> {

Expand Down Expand Up @@ -34,10 +36,19 @@ public CommandArguments add(Object arg) {
args.add((Rawable) arg);
} else if (arg instanceof byte[]) {
args.add(RawableFactory.from((byte[]) arg));
} else if (arg instanceof Integer) {
args.add(RawableFactory.from((Integer) arg));
} else if (arg instanceof Double) {
args.add(RawableFactory.from((Double) arg));
} else if (arg instanceof Boolean) {
args.add(RawableFactory.from((Boolean) arg ? 1 : 0));
} else if (arg instanceof float[]) {
args.add(RawableFactory.from(RediSearchUtil.toByteArray((float[]) arg)));
} else if (arg instanceof String) {
args.add(RawableFactory.from((String) arg));
} else if (arg instanceof Boolean) {
args.add(RawableFactory.from(Integer.toString((Boolean) arg ? 1 : 0)));
} else if (arg instanceof GeoCoordinate) {
GeoCoordinate geo = (GeoCoordinate) arg;
args.add(RawableFactory.from(geo.getLongitude() + "," + geo.getLatitude()));
} else {
args.add(RawableFactory.from(String.valueOf(arg)));
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -3110,6 +3110,14 @@ public final CommandObject<Long> spublish(byte[] channel, byte[] message) {
// Miscellaneous commands

// RediSearch commands
public final CommandObject<Long> hsetObject(String key, String field, Object value) {
return new CommandObject<>(commandArguments(HSET).key(key).add(field).add(value), BuilderFactory.LONG);
}

public final CommandObject<Long> hsetObject(String key, Map<String, Object> hash) {
return new CommandObject<>(addFlatMapArgs(commandArguments(HSET).key(key), hash), BuilderFactory.LONG);
}

private boolean isRoundRobinSearchCommand() {
if (broadcastAndRoundRobinConfig == null) {
return true;
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -6386,7 +6386,7 @@ public String srandmember(final String key) {
* @param key
* @param count if positive, return an array of distinct elements.
* If negative the behavior changes and the command is allowed to
* return the same element multiple times
* return the same element multiple times
* @return A list of randomly selected elements
*/
@Override
Expand Down Expand Up @@ -8758,7 +8758,7 @@ public long clusterKeySlot(final String key) {
public long clusterCountFailureReports(final String nodeId) {
checkIsInMultiOrPipeline();
connection.sendCommand(CLUSTER, "COUNT-FAILURE-REPORTS", nodeId);
return connection.getIntegerReply();
return connection.getIntegerReply();
}

@Override
Expand Down Expand Up @@ -8826,12 +8826,20 @@ public String clusterFailover(ClusterFailoverOption failoverOption) {
}

@Override
@Deprecated
public List<Object> clusterSlots() {
checkIsInMultiOrPipeline();
connection.sendCommand(CLUSTER, ClusterKeyword.SLOTS);
return connection.getObjectMultiBulkReply();
}

@Override
public List<ClusterShardInfo> clusterShards() {
checkIsInMultiOrPipeline();
connection.sendCommand(CLUSTER, ClusterKeyword.SHARDS);
return BuilderFactory.CLUSTER_SHARD_INFO_LIST.build(connection.getObjectMultiBulkReply());
}

@Override
public String clusterMyId() {
checkIsInMultiOrPipeline();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public static enum ClusterKeyword implements Rawable {
MEET, RESET, INFO, FAILOVER, SLOTS, NODES, REPLICAS, SLAVES, MYID, ADDSLOTS, DELSLOTS,
GETKEYSINSLOT, SETSLOT, NODE, MIGRATING, IMPORTING, STABLE, FORGET, FLUSHSLOTS, KEYSLOT,
COUNTKEYSINSLOT, SAVECONFIG, REPLICATE, LINKS, ADDSLOTSRANGE, DELSLOTSRANGE, BUMPEPOCH,
MYSHARDID;
MYSHARDID, SHARDS;

private final byte[] raw;

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/UnifiedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -3619,6 +3619,14 @@ public void psubscribe(BinaryJedisPubSub jedisPubSub, final byte[]... patterns)
// Random node commands

// RediSearch commands
public long hsetObject(String key, String field, Object value) {
return executeCommand(commandObjects.hsetObject(key, field, value));
}

public long hsetObject(String key, Map<String, Object> hash) {
return executeCommand(commandObjects.hsetObject(key, hash));
}

@Override
public String ftCreate(String indexName, IndexOptions indexOptions, Schema schema) {
return checkAndBroadcastCommand(commandObjects.ftCreate(indexName, indexOptions, schema));
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/redis/clients/jedis/commands/ClusterCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import redis.clients.jedis.args.ClusterResetType;
import redis.clients.jedis.args.ClusterFailoverOption;
import redis.clients.jedis.resps.ClusterShardInfo;

public interface ClusterCommands {

Expand Down Expand Up @@ -79,8 +80,24 @@ public interface ClusterCommands {

String clusterFailover(ClusterFailoverOption failoverOption);

/**
* {@code CLUSTER SLOTS} command is deprecated since Redis 7.
*
* @deprecated Use {@link ClusterCommands#clusterShards()}.
*/
@Deprecated
List<Object> clusterSlots();

/**
* {@code CLUSTER SHARDS} returns details about the shards of the cluster.
* This command replaces the {@code CLUSTER SLOTS} command from Redis 7,
* by providing a more efficient and extensible representation of the cluster.
*
* @return a list of shards, with each shard containing two objects, 'slots' and 'nodes'.
* @see <a href="https://redis.io/commands/cluster-shards/">CLUSTER SHARDS</a>
*/
List<ClusterShardInfo> clusterShards();

String clusterReset();

/**
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/redis/clients/jedis/resps/ClusterShardInfo.java
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;
}

}

0 comments on commit 63e0f5c

Please sign in to comment.