Skip to content

Commit

Permalink
Merge branch 'master' into key-arg-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 authored Jun 11, 2024
2 parents 9a86cce + 811dca0 commit c3d9c76
Show file tree
Hide file tree
Showing 86 changed files with 3,115 additions and 654 deletions.
6 changes: 3 additions & 3 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.17.0</jackson.version>
<jackson.version>2.17.1</jackson.version>
<maven.surefire.version>3.2.5</maven.surefire.version>
</properties>

Expand Down Expand Up @@ -272,7 +272,7 @@
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
Expand Down Expand Up @@ -306,7 +306,7 @@
<!--Sign the components - this is required by maven central for releases -->
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.3</version>
<version>3.2.4</version>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/AbstractTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ protected AbstractTransaction(CommandObjects commandObjects) {
public Response<Long> waitReplicas(int replicas, long timeout) {
return appendCommand(commandObjects.waitReplicas(replicas, timeout));
}

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));
}
}
2 changes: 2 additions & 0 deletions src/main/java/redis/clients/jedis/BuilderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ public String toString() {
}
};

@Deprecated
public static final Builder<Set<Tuple>> TUPLE_ZSET = new Builder<Set<Tuple>>() {
@Override
@SuppressWarnings("unchecked")
Expand All @@ -683,6 +684,7 @@ public String toString() {
}
};

@Deprecated
public static final Builder<Set<Tuple>> TUPLE_ZSET_RESP3 = new Builder<Set<Tuple>>() {
@Override
@SuppressWarnings("unchecked")
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/redis/clients/jedis/ClusterPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ private static ClusterCommandObjects createClusterCommandObjects(RedisProtocol p
return cco;
}

/**
* This method must be called after constructor, if graph commands are going to be used.
*/
public void prepareGraphCommands() {
super.prepareGraphCommands(provider);
}

@Override
public void close() {
try {
Expand All @@ -65,10 +72,11 @@ protected Connection getConnection(HostAndPort nodeKey) {
return provider.getConnection(nodeKey);
}

/**
* This method must be called after constructor, if graph commands are going to be used.
*/
public void prepareGraphCommands() {
super.prepareGraphCommands(provider);
public Response<Long> spublish(String channel, String message) {
return appendCommand(commandObjects.spublish(channel, message));
}

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

Expand Down Expand Up @@ -36,19 +37,50 @@ void setKeyArgumentPreProcessor(CommandKeyArgumentPreProcessor keyPreProcessor)
this.keyPreProc = keyPreProcessor;
}

public CommandArguments add(Rawable arg) {
args.add(arg);
return this;
}

public CommandArguments add(byte[] arg) {
return add(RawableFactory.from(arg));
}

public CommandArguments add(boolean arg) {
return add(RawableFactory.from(arg));
}

public CommandArguments add(int arg) {
return add(RawableFactory.from(arg));
}

public CommandArguments add(long arg) {
return add(RawableFactory.from(arg));
}

public CommandArguments add(double arg) {
return add(RawableFactory.from(arg));
}

public CommandArguments add(String arg) {
return add(RawableFactory.from(arg));
}

public CommandArguments add(Object arg) {
if (arg == null) {
throw new IllegalArgumentException("null is not a valid argument.");
} else if (arg instanceof Rawable) {
args.add((Rawable) arg);
} else if (arg instanceof byte[]) {
args.add(RawableFactory.from((byte[]) arg));
} else if (arg instanceof Boolean) {
args.add(RawableFactory.from((Boolean) arg));
} else if (arg instanceof Integer) {
args.add(RawableFactory.from((Integer) arg));
} else if (arg instanceof Long) {
args.add(RawableFactory.from((Long) 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) {
Expand Down Expand Up @@ -99,14 +131,12 @@ public CommandArguments key(Object key) {
}

public final CommandArguments keys(Object... keys) {
for (Object key : keys) {
key(key);
}
Arrays.stream(keys).forEach(this::key);
return this;
}

public final CommandArguments keys(Collection keys) {
keys.forEach(key -> key(key));
keys.forEach(this::key);
return this;
}

Expand Down
145 changes: 135 additions & 10 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -1148,10 +1148,6 @@ public final CommandObject<ScanResult<String>> hscanNoValues(String key, String
return new CommandObject<>(commandArguments(HSCAN).key(key).add(cursor).addParams(params).add(NOVALUES), BuilderFactory.SCAN_RESPONSE);
}

public final CommandObject<Long> hstrlen(String key, String field) {
return new CommandObject<>(commandArguments(HSTRLEN).key(key).add(field), BuilderFactory.LONG);
}

public final CommandObject<ScanResult<Map.Entry<byte[], byte[]>>> hscan(byte[] key, byte[] cursor, ScanParams params) {
return new CommandObject<>(commandArguments(HSCAN).key(key).add(cursor).addParams(params), BuilderFactory.HSCAN_BINARY_RESPONSE);
}
Expand All @@ -1160,9 +1156,143 @@ public final CommandObject<ScanResult<byte[]>> hscanNoValues(byte[] key, byte[]
return new CommandObject<>(commandArguments(HSCAN).key(key).add(cursor).addParams(params).add(NOVALUES), BuilderFactory.SCAN_BINARY_RESPONSE);
}

public final CommandObject<Long> hstrlen(String key, String field) {
return new CommandObject<>(commandArguments(HSTRLEN).key(key).add(field), BuilderFactory.LONG);
}

public final CommandObject<Long> hstrlen(byte[] key, byte[] field) {
return new CommandObject<>(commandArguments(HSTRLEN).key(key).add(field), BuilderFactory.LONG);
}

public final CommandObject<List<Long>> hexpire(String key, long seconds, String... fields) {
return new CommandObject<>(commandArguments(HEXPIRE).key(key).add(seconds)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hexpire(String key, long seconds, ExpiryOption condition, String... fields) {
return new CommandObject<>(commandArguments(HEXPIRE).key(key).add(seconds).add(condition)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpexpire(String key, long milliseconds, String... fields) {
return new CommandObject<>(commandArguments(HPEXPIRE).key(key).add(milliseconds)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpexpire(String key, long milliseconds, ExpiryOption condition, String... fields) {
return new CommandObject<>(commandArguments(HPEXPIRE).key(key).add(milliseconds).add(condition)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hexpireAt(String key, long unixTimeSeconds, String... fields) {
return new CommandObject<>(commandArguments(HEXPIREAT).key(key).add(unixTimeSeconds)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hexpireAt(String key, long unixTimeSeconds, ExpiryOption condition, String... fields) {
return new CommandObject<>(commandArguments(HEXPIREAT).key(key).add(unixTimeSeconds).add(condition)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpexpireAt(String key, long unixTimeMillis, String... fields) {
return new CommandObject<>(commandArguments(HPEXPIREAT).key(key).add(unixTimeMillis)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpexpireAt(String key, long unixTimeMillis, ExpiryOption condition, String... fields) {
return new CommandObject<>(commandArguments(HPEXPIREAT).key(key).add(unixTimeMillis).add(condition)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hexpire(byte[] key, long seconds, byte[]... fields) {
return new CommandObject<>(commandArguments(HEXPIRE).key(key).add(seconds)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hexpire(byte[] key, long seconds, ExpiryOption condition, byte[]... fields) {
return new CommandObject<>(commandArguments(HEXPIRE).key(key).add(seconds).add(condition)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpexpire(byte[] key, long milliseconds, byte[]... fields) {
return new CommandObject<>(commandArguments(HPEXPIRE).key(key).add(milliseconds)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpexpire(byte[] key, long milliseconds, ExpiryOption condition, byte[]... fields) {
return new CommandObject<>(commandArguments(HPEXPIRE).key(key).add(milliseconds).add(condition)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hexpireAt(byte[] key, long unixTimeSeconds, byte[]... fields) {
return new CommandObject<>(commandArguments(HEXPIREAT).key(key).add(unixTimeSeconds)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hexpireAt(byte[] key, long unixTimeSeconds, ExpiryOption condition, byte[]... fields) {
return new CommandObject<>(commandArguments(HEXPIREAT).key(key).add(unixTimeSeconds).add(condition)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpexpireAt(byte[] key, long unixTimeMillis, byte[]... fields) {
return new CommandObject<>(commandArguments(HPEXPIREAT).key(key).add(unixTimeMillis)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpexpireAt(byte[] key, long unixTimeMillis, ExpiryOption condition, byte[]... fields) {
return new CommandObject<>(commandArguments(HPEXPIREAT).key(key).add(unixTimeMillis).add(condition)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hexpireTime(String key, String... fields) {
return new CommandObject<>(commandArguments(HEXPIRETIME).key(key)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpexpireTime(String key, String... fields) {
return new CommandObject<>(commandArguments(HPEXPIRETIME).key(key)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> httl(String key, String... fields) {
return new CommandObject<>(commandArguments(HTTL).key(key)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpttl(String key, String... fields) {
return new CommandObject<>(commandArguments(HPTTL).key(key)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hexpireTime(byte[] key, byte[]... fields) {
return new CommandObject<>(commandArguments(HEXPIRETIME).key(key)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpexpireTime(byte[] key, byte[]... fields) {
return new CommandObject<>(commandArguments(HPEXPIRETIME).key(key)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> httl(byte[] key, byte[]... fields) {
return new CommandObject<>(commandArguments(HTTL).key(key)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpttl(byte[] key, byte[]... fields) {
return new CommandObject<>(commandArguments(HPTTL).key(key)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpersist(String key, String... fields) {
return new CommandObject<>(commandArguments(HPERSIST).key(key)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}

public final CommandObject<List<Long>> hpersist(byte[] key, byte[]... fields) {
return new CommandObject<>(commandArguments(HPERSIST).key(key)
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
}
// Hash commands

// Set commands
Expand Down Expand Up @@ -2028,10 +2158,6 @@ public final CommandObject<KeyValue<byte[], List<Tuple>>> bzmpop(double timeout,
private Builder<List<Tuple>> getTupleListBuilder() {
return protocol == RedisProtocol.RESP3 ? BuilderFactory.TUPLE_LIST_RESP3 : BuilderFactory.TUPLE_LIST;
}

private Builder<Set<Tuple>> getTupleSetBuilder() {
return protocol == RedisProtocol.RESP3 ? BuilderFactory.TUPLE_ZSET_RESP3 : BuilderFactory.TUPLE_ZSET;
}
// Sorted Set commands

// Geo commands
Expand Down Expand Up @@ -3503,8 +3629,7 @@ public final CommandObject<String> jsonMerge(String key, Path path, Object pojo)
}

public final CommandObject<Object> jsonGet(String key) {
return new CommandObject<>(commandArguments(JsonCommand.GET).key(key),
protocol != RedisProtocol.RESP3 ? JSON_GENERIC_OBJECT : JsonBuilderFactory.JSON_OBJECT);
return new CommandObject<>(commandArguments(JsonCommand.GET).key(key), JSON_GENERIC_OBJECT);
}

@Deprecated
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 @@ -349,7 +349,7 @@ protected Object readProtocolWithCheckingBroken() {
try {
return Protocol.read(inputStream);
// Object read = Protocol.read(inputStream);
// System.out.println(SafeEncoder.encodeObject(read));
// System.out.println(redis.clients.jedis.util.SafeEncoder.encodeObject(read));
// return read;
} catch (JedisConnectionException exc) {
broken = true;
Expand Down
Loading

0 comments on commit c3d9c76

Please sign in to comment.