Skip to content

Commit

Permalink
Merge branch 'master' into toString
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 authored Apr 4, 2024
2 parents 9b76308 + 2d42338 commit 952da8d
Show file tree
Hide file tree
Showing 272 changed files with 48,837 additions and 2,044 deletions.
20 changes: 1 addition & 19 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,10 @@ jobs:
mvn javadoc:jar
- name: Run tests
run: |
TEST="" make test
make test
env:
JVM_OPTS: -Xmx3200m
TERM: dumb
- name: sleep 10s
run: sleep 10s
- name: Make - start
run: |
make start
sleep 2s
- name: Docker - mod or stack
run: docker run -p 52567:6379 -d redis/redis-stack-server:edge
- name: Test commands - default protocol
run: mvn -Dtest="redis.clients.jedis.commands.**" test
- name: Test commands - RESP3 protocol
run: mvn -DjedisProtocol=3 -Dtest="redis.clients.jedis.commands.**" test
- name: Test module commands - default protocol
run: mvn -DmodulesDocker="localhost:52567" -Dtest="redis.clients.jedis.modules.**" test
- name: Test module commands - RESP3 protocol
run: mvn -DjedisProtocol=3 -DmodulesDocker="localhost:52567" -Dtest="redis.clients.jedis.modules.**" test
- name: Make - stop
run: make stop
- name: Codecov
run: |
bash <(curl -s https://codecov.io/bash)
84 changes: 73 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,50 @@ cluster-enabled yes
cluster-config-file /tmp/redis_cluster_node5.conf
endef

# STABLE CLUSTER REDIS NODES
# The structure of this cluster is not changed by the tests!
define REDIS_STABLE_CLUSTER_NODE1_CONF
daemonize yes
protected-mode no
requirepass cluster
port 7479
cluster-node-timeout 15000
pidfile /tmp/redis_stable_cluster_node1.pid
logfile /tmp/redis_stable_cluster_node1.log
save ""
appendonly no
cluster-enabled yes
cluster-config-file /tmp/redis_stable_cluster_node1.conf
endef

define REDIS_STABLE_CLUSTER_NODE2_CONF
daemonize yes
protected-mode no
requirepass cluster
port 7480
cluster-node-timeout 15000
pidfile /tmp/redis_stable_cluster_node2.pid
logfile /tmp/redis_stable_cluster_node2.log
save ""
appendonly no
cluster-enabled yes
cluster-config-file /tmp/redis_stable_cluster_node2.conf
endef

define REDIS_STABLE_CLUSTER_NODE3_CONF
daemonize yes
protected-mode no
requirepass cluster
port 7481
cluster-node-timeout 15000
pidfile /tmp/redis_stable_cluster_node3.pid
logfile /tmp/redis_stable_cluster_node3.log
save ""
appendonly no
cluster-enabled yes
cluster-config-file /tmp/redis_stable_cluster_node3.conf
endef

# UDS REDIS NODES
define REDIS_UDS
daemonize yes
Expand Down Expand Up @@ -355,6 +399,9 @@ export REDIS_CLUSTER_NODE2_CONF
export REDIS_CLUSTER_NODE3_CONF
export REDIS_CLUSTER_NODE4_CONF
export REDIS_CLUSTER_NODE5_CONF
export REDIS_STABLE_CLUSTER_NODE1_CONF
export REDIS_STABLE_CLUSTER_NODE2_CONF
export REDIS_STABLE_CLUSTER_NODE3_CONF
export REDIS_UDS
export REDIS_UNAVAILABLE_CONF
export STUNNEL_CONF
Expand All @@ -366,7 +413,7 @@ ifndef STUNNEL_BIN
endif
export SKIP_SSL

start: stunnel cleanup
start: stunnel cleanup compile-module
echo "$$REDIS1_CONF" | redis-server -
echo "$$REDIS2_CONF" | redis-server -
echo "$$REDIS3_CONF" | redis-server -
Expand All @@ -393,8 +440,13 @@ start: stunnel cleanup
echo "$$REDIS_CLUSTER_NODE3_CONF" | redis-server -
echo "$$REDIS_CLUSTER_NODE4_CONF" | redis-server -
echo "$$REDIS_CLUSTER_NODE5_CONF" | redis-server -
echo "$$REDIS_STABLE_CLUSTER_NODE1_CONF" | redis-server -
echo "$$REDIS_STABLE_CLUSTER_NODE2_CONF" | redis-server -
echo "$$REDIS_STABLE_CLUSTER_NODE3_CONF" | redis-server -
echo "$$REDIS_UDS" | redis-server -
echo "$$REDIS_UNAVAILABLE_CONF" | redis-server -
redis-cli -a cluster --cluster create 127.0.0.1:7479 127.0.0.1:7480 127.0.0.1:7481 --cluster-yes
docker run -p 6479:6379 --name jedis-stack -d redis/redis-stack-server:edge

cleanup:
- rm -vf /tmp/redis_cluster_node*.conf 2>/dev/null
Expand All @@ -404,6 +456,7 @@ stunnel:
@if [ -e "$$STUNNEL_BIN" ]; then\
echo "$$STUNNEL_CONF" | stunnel -fd 0;\
fi

stop:
kill `cat /tmp/redis1.pid`
kill `cat /tmp/redis2.pid`
Expand All @@ -426,6 +479,9 @@ stop:
kill `cat /tmp/redis_cluster_node3.pid` || true
kill `cat /tmp/redis_cluster_node4.pid` || true
kill `cat /tmp/redis_cluster_node5.pid` || true
kill `cat /tmp/redis_stable_cluster_node1.pid`
kill `cat /tmp/redis_stable_cluster_node2.pid`
kill `cat /tmp/redis_stable_cluster_node3.pid`
kill `cat /tmp/redis_uds.pid` || true
kill `cat /tmp/stunnel.pid` || true
[ -f /tmp/redis_unavailable.pid ] && kill `cat /tmp/redis_unavailable.pid` || true
Expand All @@ -439,29 +495,35 @@ stop:
rm -f /tmp/redis_cluster_node3.conf
rm -f /tmp/redis_cluster_node4.conf
rm -f /tmp/redis_cluster_node5.conf
rm -f /tmp/redis_stable_cluster_node1.conf
rm -f /tmp/redis_stable_cluster_node2.conf
rm -f /tmp/redis_stable_cluster_node3.conf
docker rm -f jedis-stack

test: compile-module start
sleep 2
test: | start mvn-test stop

mvn-test:
mvn -Dtest=${SKIP_SSL}${TEST} clean compile test
make stop

package: start
package: | start mvn-package stop

mvn-package:
mvn clean package
make stop

deploy: start
deploy: | start mvn-deploy stop

mvn-deploy:
mvn clean deploy
make stop

format:
mvn java-formatter:format

release:
make start
release: | start mvn-release stop

mvn-release:
mvn release:clean
mvn release:prepare
mvn release:perform -DskipTests
make stop

system-setup:
sudo apt install -y gcc g++
Expand Down
14 changes: 10 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<jedis.module.name>redis.clients.jedis</jedis.module.name>
<slf4j.version>1.7.36</slf4j.version>
<resilience4j.version>1.7.1</resilience4j.version>
<jackson.version>2.16.1</jackson.version>
<jackson.version>2.17.0</jackson.version>
<maven.surefire.version>3.2.5</maven.surefire.version>
</properties>

Expand All @@ -67,7 +67,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20240205</version>
<version>20240303</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down Expand Up @@ -127,6 +127,12 @@
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit</artifactId>
<version>2.38.0</version> <!-- 3.x requires Java 17 -->
<scope>test</scope>
</dependency>

<!-- circuit breaker / failover -->
<dependency>
Expand Down Expand Up @@ -189,7 +195,7 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<version>3.13.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand Down Expand Up @@ -300,7 +306,7 @@
<!--Sign the components - this is required by maven central for releases -->
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.2</version>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/redis/clients/jedis/AbstractTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ protected AbstractTransaction() {
super(new CommandObjects());
}

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

public abstract void multi();

/**
Expand Down
54 changes: 41 additions & 13 deletions src/main/java/redis/clients/jedis/BuilderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -1420,10 +1420,10 @@ public List<Map.Entry<String, List<StreamEntry>>> build(Object data) {
.collect(Collectors.toList());
} else {
List<Map.Entry<String, List<StreamEntry>>> result = new ArrayList<>(list.size());
for (Object streamObj : list) {
List<Object> stream = (List<Object>) streamObj;
String streamKey = STRING.build(stream.get(0));
List<StreamEntry> streamEntries = STREAM_ENTRY_LIST.build(stream.get(1));
for (Object anObj : list) {
List<Object> streamObj = (List<Object>) anObj;
String streamKey = STRING.build(streamObj.get(0));
List<StreamEntry> streamEntries = STREAM_ENTRY_LIST.build(streamObj.get(1));
result.add(KeyValue.of(streamKey, streamEntries));
}
return result;
Expand All @@ -1436,6 +1436,35 @@ public String toString() {
}
};

public static final Builder<Map<String, List<StreamEntry>>> STREAM_READ_MAP_RESPONSE
= new Builder<Map<String, List<StreamEntry>>>() {
@Override
public Map<String, List<StreamEntry>> build(Object data) {
if (data == null) return null;
List list = (List) data;
if (list.isEmpty()) return Collections.emptyMap();

if (list.get(0) instanceof KeyValue) {
return ((List<KeyValue>) list).stream()
.collect(Collectors.toMap(kv -> STRING.build(kv.getKey()), kv -> STREAM_ENTRY_LIST.build(kv.getValue())));
} else {
Map<String, List<StreamEntry>> result = new HashMap<>(list.size());
for (Object anObj : list) {
List<Object> streamObj = (List<Object>) anObj;
String streamKey = STRING.build(streamObj.get(0));
List<StreamEntry> streamEntries = STREAM_ENTRY_LIST.build(streamObj.get(1));
result.put(streamKey, streamEntries);
}
return result;
}
}

@Override
public String toString() {
return "Map<String, List<StreamEntry>>";
}
};

public static final Builder<List<StreamPendingEntry>> STREAM_PENDING_ENTRY_LIST = new Builder<List<StreamPendingEntry>>() {
@Override
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -1783,15 +1812,14 @@ public StreamPendingSummary build(Object data) {
}

List<Object> objectList = (List<Object>) data;
long total = BuilderFactory.LONG.build(objectList.get(0));
String minId = SafeEncoder.encode((byte[]) objectList.get(1));
String maxId = SafeEncoder.encode((byte[]) objectList.get(2));
List<List<Object>> consumerObjList = (List<List<Object>>) objectList.get(3);
Map<String, Long> map = new HashMap<>(consumerObjList.size());
for (List<Object> consumerObj : consumerObjList) {
map.put(SafeEncoder.encode((byte[]) consumerObj.get(0)), Long.parseLong(SafeEncoder.encode((byte[]) consumerObj.get(1))));
}
return new StreamPendingSummary(total, new StreamEntryID(minId), new StreamEntryID(maxId), map);
long total = LONG.build(objectList.get(0));
StreamEntryID minId = STREAM_ENTRY_ID.build(objectList.get(1));
StreamEntryID maxId = STREAM_ENTRY_ID.build(objectList.get(2));
Map<String, Long> map = objectList.get(3) == null ? null
: ((List<List<Object>>) objectList.get(3)).stream().collect(
Collectors.toMap(pair -> STRING.build(pair.get(0)),
pair -> Long.parseLong(STRING.build(pair.get(1)))));
return new StreamPendingSummary(total, minId, maxId, map);
}

@Override
Expand Down
38 changes: 34 additions & 4 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ public final CommandObject<String> setGet(String key, String value) {
}

public final CommandObject<String> setGet(String key, String value, SetParams params) {
return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).addParams(params)
.add(Keyword.GET), BuilderFactory.STRING);
return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).addParams(params).add(Keyword.GET),
BuilderFactory.STRING);
}

public final CommandObject<String> getDel(String key) {
Expand All @@ -468,8 +468,8 @@ public final CommandObject<byte[]> setGet(byte[] key, byte[] value) {
}

public final CommandObject<byte[]> setGet(byte[] key, byte[] value, SetParams params) {
return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).addParams(params)
.add(Keyword.GET), BuilderFactory.BINARY);
return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).addParams(params).add(Keyword.GET),
BuilderFactory.BINARY);
}

public final CommandObject<byte[]> getDel(byte[] key) {
Expand All @@ -480,10 +480,18 @@ public final CommandObject<byte[]> getEx(byte[] key, GetExParams params) {
return new CommandObject<>(commandArguments(Command.GETEX).key(key).addParams(params), BuilderFactory.BINARY);
}

/**
* @deprecated Use {@link CommandObjects#setGet(java.lang.String, java.lang.String)}.
*/
@Deprecated
public final CommandObject<String> getSet(String key, String value) {
return new CommandObject<>(commandArguments(Command.GETSET).key(key).add(value), BuilderFactory.STRING);
}

/**
* @deprecated Use {@link CommandObjects#setGet(byte[], byte[])}.
*/
@Deprecated
public final CommandObject<byte[]> getSet(byte[] key, byte[] value) {
return new CommandObject<>(commandArguments(Command.GETSET).key(key).add(value), BuilderFactory.BINARY);
}
Expand Down Expand Up @@ -2658,6 +2666,15 @@ public final CommandObject<List<Map.Entry<String, List<StreamEntry>>>> xread(
return new CommandObject<>(args, BuilderFactory.STREAM_READ_RESPONSE);
}

public final CommandObject<Map<String, List<StreamEntry>>> xreadAsMap(
XReadParams xReadParams, Map<String, StreamEntryID> streams) {
CommandArguments args = commandArguments(XREAD).addParams(xReadParams).add(STREAMS);
Set<Map.Entry<String, StreamEntryID>> entrySet = streams.entrySet();
entrySet.forEach(entry -> args.key(entry.getKey()));
entrySet.forEach(entry -> args.add(entry.getValue()));
return new CommandObject<>(args, BuilderFactory.STREAM_READ_MAP_RESPONSE);
}

public final CommandObject<List<Map.Entry<String, List<StreamEntry>>>> xreadGroup(
String groupName, String consumer, XReadGroupParams xReadGroupParams,
Map<String, StreamEntryID> streams) {
Expand All @@ -2670,6 +2687,18 @@ public final CommandObject<List<Map.Entry<String, List<StreamEntry>>>> xreadGrou
return new CommandObject<>(args, BuilderFactory.STREAM_READ_RESPONSE);
}

public final CommandObject<Map<String, List<StreamEntry>>> xreadGroupAsMap(
String groupName, String consumer, XReadGroupParams xReadGroupParams,
Map<String, StreamEntryID> streams) {
CommandArguments args = commandArguments(XREADGROUP)
.add(GROUP).add(groupName).add(consumer)
.addParams(xReadGroupParams).add(STREAMS);
Set<Map.Entry<String, StreamEntryID>> entrySet = streams.entrySet();
entrySet.forEach(entry -> args.key(entry.getKey()));
entrySet.forEach(entry -> args.add(entry.getValue()));
return new CommandObject<>(args, BuilderFactory.STREAM_READ_MAP_RESPONSE);
}

public final CommandObject<List<Object>> xread(XReadParams xReadParams, Map.Entry<byte[], byte[]>... streams) {
CommandArguments args = commandArguments(XREAD).addParams(xReadParams).add(STREAMS);
for (Map.Entry<byte[], byte[]> entry : streams) {
Expand Down Expand Up @@ -3594,6 +3623,7 @@ public final CommandObject<Double> jsonNumIncrBy(String key, Path path, double v
return new CommandObject<>(commandArguments(JsonCommand.NUMINCRBY).key(key).add(path).add(value), BuilderFactory.DOUBLE);
}

@Deprecated
public final CommandObject<Long> jsonArrAppend(String key, String path, JSONObject... objects) {
CommandArguments args = commandArguments(JsonCommand.ARRAPPEND).key(key).add(path);
for (Object object : objects) {
Expand Down
Loading

0 comments on commit 952da8d

Please sign in to comment.