Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-besga-panel authored Dec 9, 2023
2 parents ad4f0d7 + be088e3 commit 32a570a
Show file tree
Hide file tree
Showing 35 changed files with 5,643 additions and 8,811 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.txt)
[![Integration](https://github.com/redis/jedis/actions/workflows/integration.yml/badge.svg?branch=master)](https://github.com/redis/jedis/actions/workflows/integration.yml)
[![codecov](https://codecov.io/gh/redis/jedis/branch/master/graph/badge.svg?token=pAstxAAjYo)](https://codecov.io/gh/redis/jedis)
[![Discord](https://img.shields.io/discord/697882427875393627?style=flat-square)](https://discord.gg/qRhBuY8Z)
[![Discord](https://img.shields.io/discord/697882427875393627?style=flat-square)](https://discord.gg/redis)

## What is Jedis?

Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<packaging>jar</packaging>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>5.1.0-SNAPSHOT</version>
<version>5.2.0-SNAPSHOT</version>
<name>Jedis</name>
<description>Jedis is a blazingly small and sane Redis java client.</description>
<url>https://github.com/redis/jedis</url>
Expand Down Expand Up @@ -192,7 +192,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 @@ -220,7 +220,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 @@ -321,7 +321,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
26 changes: 26 additions & 0 deletions src/main/java/redis/clients/jedis/AbstractPipeline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package redis.clients.jedis;

import java.io.Closeable;

public abstract class AbstractPipeline extends PipeliningBase implements Closeable {

protected AbstractPipeline(CommandObjects commandObjects) {
super(commandObjects);
}

@Override
public abstract void close();

/**
* Synchronize pipeline by reading all responses.
*/
public abstract void sync();

public Response<Long> publish(String channel, String message) {
return appendCommand(commandObjects.publish(channel, message));
}

public Response<Long> publish(byte[] channel, byte[] message) {
return appendCommand(commandObjects.publish(channel, message));
}
}
35 changes: 35 additions & 0 deletions src/main/java/redis/clients/jedis/AbstractTransaction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package redis.clients.jedis;

import java.io.Closeable;
import java.util.List;

public abstract class AbstractTransaction extends PipeliningBase implements Closeable {

protected AbstractTransaction() {
super(new CommandObjects());
}

public abstract void multi();

/**
* Must be called before {@link AbstractTransaction#multi() MULTI}.
*/
public abstract String watch(final String... keys);

/**
* Must be called before {@link AbstractTransaction#multi() MULTI}.
*/
public abstract String watch(final byte[]... keys);

public abstract String unwatch();

@Override public abstract void close();

public abstract List<Object> exec();

public abstract String discard();

public Response<Long> waitReplicas(int replicas, long timeout) {
return appendCommand(commandObjects.waitReplicas(replicas, timeout));
}
}
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
12 changes: 11 additions & 1 deletion src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ public class CommandObjects {

private RedisProtocol protocol;

protected void setProtocol(RedisProtocol proto) {
// TODO: restrict?
public final void setProtocol(RedisProtocol proto) {
this.protocol = proto;
}

// TODO: remove?
protected RedisProtocol getProtocol() {
return protocol;
}
Expand Down Expand Up @@ -3110,6 +3112,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
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public String toString() {
return "Connection{" + socketFactory + "}";
}

final RedisProtocol getRedisProtocol() {
public final RedisProtocol getRedisProtocol() {
return protocol;
}

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
7 changes: 1 addition & 6 deletions src/main/java/redis/clients/jedis/MultiNodePipelineBase.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package redis.clients.jedis;

import java.io.Closeable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
Expand All @@ -14,16 +13,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import redis.clients.jedis.commands.PipelineBinaryCommands;
import redis.clients.jedis.commands.PipelineCommands;
import redis.clients.jedis.commands.RedisModulePipelineCommands;
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.graph.GraphCommandObjects;
import redis.clients.jedis.providers.ConnectionProvider;
import redis.clients.jedis.util.IOUtils;

public abstract class MultiNodePipelineBase extends PipelineBase
implements PipelineCommands, PipelineBinaryCommands, RedisModulePipelineCommands, Closeable {
public abstract class MultiNodePipelineBase extends PipelineBase {

private final Logger log = LoggerFactory.getLogger(getClass());

Expand Down
Loading

0 comments on commit 32a570a

Please sign in to comment.