Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshi5012 authored Apr 21, 2023
2 parents 923ad73 + b2c5acf commit edd0530
Show file tree
Hide file tree
Showing 23 changed files with 446 additions and 65 deletions.
16 changes: 16 additions & 0 deletions src/main/java/redis/clients/jedis/BuilderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,22 @@ public String toString() {
}
};

public static final Builder<KeyValue<Long, Double>> ZRANK_WITHSCORE_PAIR = new Builder<KeyValue<Long, Double>>() {
@Override
public KeyValue<Long, Double> build(Object data) {
if (data == null) {
return null;
}
List<Object> l = (List<Object>) data;
return new KeyValue<>(LONG.build(l.get(0)), DOUBLE.build(l.get(1)));
}

@Override
public String toString() {
return "KeyValue<Long, Double>";
}
};

public static final Builder<KeyValue<String, List<String>>> KEYED_STRING_LIST
= new Builder<KeyValue<String, List<String>>>() {
@Override
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,14 @@ public final CommandObject<Long> zrevrank(String key, String member) {
return new CommandObject<>(commandArguments(ZREVRANK).key(key).add(member), BuilderFactory.LONG);
}

public final CommandObject<KeyValue<Long, Double>> zrankWithScore(String key, String member) {
return new CommandObject<>(commandArguments(ZRANK).key(key).add(member).add(WITHSCORE), BuilderFactory.ZRANK_WITHSCORE_PAIR);
}

public final CommandObject<KeyValue<Long, Double>> zrevrankWithScore(String key, String member) {
return new CommandObject<>(commandArguments(ZREVRANK).key(key).add(member).add(WITHSCORE), BuilderFactory.ZRANK_WITHSCORE_PAIR);
}

public final CommandObject<Long> zrank(byte[] key, byte[] member) {
return new CommandObject<>(commandArguments(ZRANK).key(key).add(member), BuilderFactory.LONG);
}
Expand All @@ -1388,6 +1396,14 @@ public final CommandObject<Long> zrevrank(byte[] key, byte[] member) {
return new CommandObject<>(commandArguments(ZREVRANK).key(key).add(member), BuilderFactory.LONG);
}

public final CommandObject<KeyValue<Long, Double>> zrankWithScore(byte[] key, byte[] member) {
return new CommandObject<>(commandArguments(ZRANK).key(key).add(member).add(WITHSCORE), BuilderFactory.ZRANK_WITHSCORE_PAIR);
}

public final CommandObject<KeyValue<Long, Double>> zrevrankWithScore(byte[] key, byte[] member) {
return new CommandObject<>(commandArguments(ZREVRANK).key(key).add(member).add(WITHSCORE), BuilderFactory.ZRANK_WITHSCORE_PAIR);
}

public final CommandObject<String> zrandmember(String key) {
return new CommandObject<>(commandArguments(ZRANDMEMBER).key(key), BuilderFactory.STRING);
}
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,32 @@ public Long zrevrank(final byte[] key, final byte[] member) {
return connection.executeCommand(commandObjects.zrevrank(key, member));
}

/**
* Returns the rank and the score of member in the sorted set stored at key, with the scores
* ordered from low to high.
* @param key the key
* @param member the member
* @return the KeyValue contains rank and score.
*/
@Override
public KeyValue<Long, Double> zrankWithScore(byte[] key, byte[] member) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.zrankWithScore(key, member));
}

/**
* Returns the rank and the score of member in the sorted set stored at key, with the scores
* ordered from high to low.
* @param key the key
* @param member the member
* @return the KeyValue contains rank and score.
*/
@Override
public KeyValue<Long, Double> zrevrankWithScore(byte[] key, byte[] member) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.zrevrankWithScore(key, member));
}

@Override
public List<byte[]> zrevrange(final byte[] key, final long start, final long stop) {
checkIsInMultiOrPipeline();
Expand Down Expand Up @@ -6559,6 +6585,32 @@ public Long zrevrank(final String key, final String member) {
return connection.executeCommand(commandObjects.zrevrank(key, member));
}

/**
* Returns the rank and the score of member in the sorted set stored at key, with the scores
* ordered from low to high.
* @param key the key
* @param member the member
* @return the KeyValue contains rank and score.
*/
@Override
public KeyValue<Long, Double> zrankWithScore(String key, String member) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.zrankWithScore(key, member));
}

/**
* Returns the rank and the score of member in the sorted set stored at key, with the scores
* ordered from high to low.
* @param key the key
* @param member the member
* @return the KeyValue contains rank and score.
*/
@Override
public KeyValue<Long, Double> zrevrankWithScore(String key, String member) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.zrevrankWithScore(key, member));
}

@Override
public List<String> zrevrange(final String key, final long start, final long stop) {
checkIsInMultiOrPipeline();
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/redis/clients/jedis/MultiNodePipelineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,16 @@ public Response<Long> zrevrank(String key, String member) {
return appendCommand(commandObjects.zrevrank(key, member));
}

@Override
public Response<KeyValue<Long, Double>> zrankWithScore(String key, String member) {
return appendCommand(commandObjects.zrankWithScore(key, member));
}

@Override
public Response<KeyValue<Long, Double>> zrevrankWithScore(String key, String member) {
return appendCommand(commandObjects.zrevrankWithScore(key, member));
}

@Override
public Response<List<String>> zrange(String key, long start, long stop) {
return appendCommand(commandObjects.zrange(key, start, stop));
Expand Down Expand Up @@ -2724,6 +2734,16 @@ public Response<Long> zrevrank(byte[] key, byte[] member) {
return appendCommand(commandObjects.zrevrank(key, member));
}

@Override
public Response<KeyValue<Long, Double>> zrankWithScore(byte[] key, byte[] member) {
return appendCommand(commandObjects.zrankWithScore(key, member));
}

@Override
public Response<KeyValue<Long, Double>> zrevrankWithScore(byte[] key, byte[] member) {
return appendCommand(commandObjects.zrevrankWithScore(key, member));
}

@Override
public Response<List<byte[]>> zrange(byte[] key, long start, long stop) {
return appendCommand(commandObjects.zrange(key, start, stop));
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/redis/clients/jedis/Pipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,16 @@ public Response<Long> zrevrank(String key, String member) {
return appendCommand(commandObjects.zrevrank(key, member));
}

@Override
public Response<KeyValue<Long, Double>> zrankWithScore(String key, String member) {
return appendCommand(commandObjects.zrankWithScore(key, member));
}

@Override
public Response<KeyValue<Long, Double>> zrevrankWithScore(String key, String member) {
return appendCommand(commandObjects.zrevrankWithScore(key, member));
}

@Override
public Response<List<String>> zrange(String key, long start, long stop) {
return appendCommand(commandObjects.zrange(key, start, stop));
Expand Down Expand Up @@ -2675,6 +2685,16 @@ public Response<Long> zrevrank(byte[] key, byte[] member) {
return appendCommand(commandObjects.zrevrank(key, member));
}

@Override
public Response<KeyValue<Long, Double>> zrankWithScore(byte[] key, byte[] member) {
return appendCommand(commandObjects.zrankWithScore(key, member));
}

@Override
public Response<KeyValue<Long, Double>> zrevrankWithScore(byte[] key, byte[] member) {
return appendCommand(commandObjects.zrevrankWithScore(key, member));
}

@Override
public Response<List<byte[]>> zrange(byte[] key, long start, long stop) {
return appendCommand(commandObjects.zrange(key, start, stop));
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 @@ -253,7 +253,7 @@ public byte[] getRaw() {

public static enum Keyword implements Rawable {

AGGREGATE, ALPHA, BY, GET, LIMIT, NO, NOSORT, ONE, SET, STORE, WEIGHTS, WITHSCORES, RESETSTAT,
AGGREGATE, ALPHA, BY, GET, LIMIT, NO, NOSORT, ONE, SET, STORE, WEIGHTS, WITHSCORE, WITHSCORES, RESETSTAT,
REWRITE, RESET, FLUSH, EXISTS, LOAD, LEN, HELP, SCHEDULE, MATCH, COUNT, TYPE, KEYS, REFCOUNT,
ENCODING, IDLETIME, FREQ, REPLACE, GETNAME, SETNAME, SETINFO, LIST, ID, KILL, PAUSE, UNPAUSE, UNBLOCK,
STREAMS, CREATE, MKSTREAM, SETID, DESTROY, DELCONSUMER, MAXLEN, GROUP, IDLE, TIME, BLOCK, NOACK,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
package redis.clients.jedis;

import java.util.Collection;
import java.util.function.Function;

import redis.clients.jedis.params.ScanParams;
import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.providers.ConnectionProvider;
import redis.clients.jedis.resps.ScanResult;
import redis.clients.jedis.util.JedisRoundRobinBase;
import redis.clients.jedis.util.JedisCommandIterationBase;

public class ScanRoundRobin extends JedisRoundRobinBase<ScanResult<String>> {
public class ScanIteration extends JedisCommandIterationBase<ScanResult<String>, String> {

private final int count;
private final Function<String, CommandArguments> args;

public ScanRoundRobin(ConnectionProvider connectionProvider, int batchCount, String match) {
public ScanIteration(ConnectionProvider connectionProvider, int batchCount, String match) {
super(connectionProvider, BuilderFactory.SCAN_RESPONSE);
this.count = batchCount;
this.args = (cursor) -> new CommandArguments(Protocol.Command.SCAN).add(cursor)
.add(Keyword.MATCH).add(match).add(Keyword.COUNT).add(count);
}

public ScanRoundRobin(ConnectionProvider connectionProvider, int batchCount, String match, String type) {
public ScanIteration(ConnectionProvider connectionProvider, int batchCount, String match, String type) {
super(connectionProvider, BuilderFactory.SCAN_RESPONSE);
this.count = batchCount;
this.args = (cursor) -> new CommandArguments(Protocol.Command.SCAN).add(cursor)
.add(Keyword.MATCH).add(match).add(Keyword.COUNT).add(count).add(Keyword.TYPE).add(type);
}

@Override
protected boolean isIterationCompleted(ScanResult<String> reply) {
protected boolean isNodeCompleted(ScanResult<String> reply) {
return reply.isCompleteIteration();
}

Expand All @@ -40,4 +42,9 @@ protected CommandArguments initCommandArguments() {
protected CommandArguments nextCommandArguments(ScanResult<String> lastReply) {
return args.apply(lastReply.getCursor());
}

@Override
protected Collection<String> convertBatchToData(ScanResult<String> batch) {
return batch.getResult();
}
}
20 changes: 20 additions & 0 deletions src/main/java/redis/clients/jedis/TransactionBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,16 @@ public Response<Long> zrevrank(String key, String member) {
return appendCommand(commandObjects.zrevrank(key, member));
}

@Override
public Response<KeyValue<Long, Double>> zrankWithScore(String key, String member) {
return appendCommand(commandObjects.zrankWithScore(key, member));
}

@Override
public Response<KeyValue<Long, Double>> zrevrankWithScore(String key, String member) {
return appendCommand(commandObjects.zrevrankWithScore(key, member));
}

@Override
public Response<List<String>> zrange(String key, long start, long stop) {
return appendCommand(commandObjects.zrange(key, start, stop));
Expand Down Expand Up @@ -2774,6 +2784,16 @@ public Response<Long> zrevrank(byte[] key, byte[] member) {
return appendCommand(commandObjects.zrevrank(key, member));
}

@Override
public Response<KeyValue<Long, Double>> zrankWithScore(byte[] key, byte[] member) {
return appendCommand(commandObjects.zrankWithScore(key, member));
}

@Override
public Response<KeyValue<Long, Double>> zrevrankWithScore(byte[] key, byte[] member) {
return appendCommand(commandObjects.zrevrankWithScore(key, member));
}

@Override
public Response<List<byte[]>> zrange(byte[] key, long start, long stop) {
return appendCommand(commandObjects.zrange(key, start, stop));
Expand Down
Loading

0 comments on commit edd0530

Please sign in to comment.