Skip to content

Commit

Permalink
Merge pull request quarkusio#36580 from Ladicek/redis-known-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
cescoffier authored Oct 19, 2023
2 parents 46ae60c + 04c98fd commit d35d52f
Show file tree
Hide file tree
Showing 10 changed files with 470 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class AbstractListCommands<K, V> extends ReactiveSortable<K, V> {

protected static final LPosArgs DEFAULT_INSTANCE = new LPosArgs();

public static final Command LMPOP = Command.create("lmpop");
public static final Command BLMPOP = Command.create("blmpop");

AbstractListCommands(RedisCommandExecutor redis, Type k, Type v) {
super(redis, new Marshaller(k, v), v);
this.typeOfKey = k;
Expand Down Expand Up @@ -59,7 +56,7 @@ Uni<Response> _blmpop(Duration timeout, Position position, K... keys) {
notNullOrEmpty(keys, "keys");
doesNotContainNull(keys, "keys");
validate(timeout, "timeout");
RedisCommand cmd = RedisCommand.of(BLMPOP);
RedisCommand cmd = RedisCommand.of(Command.BLMPOP);
cmd.put(timeout.toSeconds());
cmd.put(keys.length);
cmd.putAll(marshaller.encode(keys));
Expand Down Expand Up @@ -97,7 +94,7 @@ Uni<Response> _blmpop(Duration timeout, Position position, int count, K... keys)
validate(timeout, "timeout");
positive(count, "count");

RedisCommand cmd = RedisCommand.of(BLMPOP);
RedisCommand cmd = RedisCommand.of(Command.BLMPOP);
cmd.put(timeout.toSeconds());
cmd.put(keys.length);
cmd.putAll(marshaller.encode(keys));
Expand Down Expand Up @@ -203,7 +200,7 @@ Uni<Response> _lmpop(Position position, K... keys) {
notNullOrEmpty(keys, "keys");
doesNotContainNull(keys, "keys");

RedisCommand cmd = RedisCommand.of(LMPOP);
RedisCommand cmd = RedisCommand.of(Command.LMPOP);
cmd.put(keys.length);
cmd.putAll(marshaller.encode(keys));
cmd.put(position.name());
Expand All @@ -216,7 +213,7 @@ Uni<Response> _lmpop(Position position, int count, K... keys) {
doesNotContainNull(keys, "keys");
positive(count, "count");

RedisCommand cmd = RedisCommand.of(LMPOP);
RedisCommand cmd = RedisCommand.of(Command.LMPOP);
cmd.put(keys.length);
cmd.putAll(marshaller.encode(keys));
cmd.put(position.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class AbstractSetCommands<K, V> extends ReactiveSortable<K, V> {

protected final Type typeOfValue;

public static final Command SINTERCARD = Command.create("sintercard");

AbstractSetCommands(RedisCommandExecutor redis, Type k, Type v) {
super(redis, new Marshaller(k, v), v);
this.typeOfValue = v;
Expand Down Expand Up @@ -80,7 +78,7 @@ Uni<Response> _sintercard(K... keys) {
throw new IllegalArgumentException("`keys` must contain at least 2 keys");
}

RedisCommand cmd = RedisCommand.of(SINTERCARD).put(keys.length).putAll(marshaller.encode(keys));
RedisCommand cmd = RedisCommand.of(Command.SINTERCARD).put(keys.length).putAll(marshaller.encode(keys));
return execute(cmd);
}

Expand All @@ -94,7 +92,7 @@ Uni<Response> _sintercard(int limit, K... keys) {
throw new IllegalArgumentException("`keys` must contain at least 2 keys");
}

RedisCommand cmd = RedisCommand.of(SINTERCARD).put(keys.length).putAll(marshaller.encode(keys))
RedisCommand cmd = RedisCommand.of(Command.SINTERCARD).put(keys.length).putAll(marshaller.encode(keys))
.put("LIMIT").put(limit);
return execute(cmd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ class AbstractSortedSetCommands<K, V> extends ReactiveSortable<K, V> {
protected static final ZAggregateArgs DEFAULT_INSTANCE_AGG = new ZAggregateArgs();
protected static final ZRangeArgs DEFAULT_INSTANCE_RANGE = new ZRangeArgs();

public static final Command ZINTERCARD = Command.create("zintercard");
public static final Command ZMPOP = Command.create("zmpop");
public static final Command BZMPOP = Command.create("bzmpop");

AbstractSortedSetCommands(RedisCommandExecutor redis, Type k, Type v) {
super(redis, new Marshaller(k, v), v);
this.typeOfValue = v;
Expand Down Expand Up @@ -237,7 +233,7 @@ Uni<Response> _zintercard(K... keys) {
if (keys.length < 2) {
throw new IllegalArgumentException("Need at least two keys");
}
RedisCommand cmd = RedisCommand.of(ZINTERCARD)
RedisCommand cmd = RedisCommand.of(Command.ZINTERCARD)
.put(keys.length);

for (K key : keys) {
Expand All @@ -254,7 +250,7 @@ Uni<Response> _zintercard(long limit, K... keys) {
throw new IllegalArgumentException("Need at least two keys");
}
positive(limit, "limit");
RedisCommand cmd = RedisCommand.of(ZINTERCARD)
RedisCommand cmd = RedisCommand.of(Command.ZINTERCARD)
.put(keys.length);

for (K key : keys) {
Expand Down Expand Up @@ -301,32 +297,32 @@ Uni<Response> _zlexcount(K key, Range<String> range) {
Uni<Response> _zmpopMin(K... keys) {
notNullOrEmpty(keys, "keys");
doesNotContainNull(keys, "keys");
RedisCommand cmd = RedisCommand.of(ZMPOP).put(keys.length).putAll(marshaller.encode(keys)).put("MIN");
RedisCommand cmd = RedisCommand.of(Command.ZMPOP).put(keys.length).putAll(marshaller.encode(keys)).put("MIN");
return execute(cmd);
}

Uni<Response> _zmpopMin(int count, K... keys) {
notNullOrEmpty(keys, "keys");
doesNotContainNull(keys, "keys");
positive(count, "count");
RedisCommand cmd = RedisCommand.of(ZMPOP).put(keys.length).putAll(marshaller.encode(keys)).put("MIN").put("COUNT")
.put(count);
RedisCommand cmd = RedisCommand.of(Command.ZMPOP).put(keys.length).putAll(marshaller.encode(keys)).put("MIN")
.put("COUNT").put(count);
return execute(cmd);
}

Uni<Response> _zmpopMax(K... keys) {
notNullOrEmpty(keys, "keys");
doesNotContainNull(keys, "keys");
RedisCommand cmd = RedisCommand.of(ZMPOP).put(keys.length).putAll(marshaller.encode(keys)).put("MAX");
RedisCommand cmd = RedisCommand.of(Command.ZMPOP).put(keys.length).putAll(marshaller.encode(keys)).put("MAX");
return execute(cmd);
}

Uni<Response> _zmpopMax(int count, K... keys) {
notNullOrEmpty(keys, "keys");
doesNotContainNull(keys, "keys");
positive(count, "count");
RedisCommand cmd = RedisCommand.of(ZMPOP).put(keys.length).putAll(marshaller.encode(keys)).put("MAX").put("COUNT")
.put(count);
RedisCommand cmd = RedisCommand.of(Command.ZMPOP).put(keys.length).putAll(marshaller.encode(keys)).put("MAX")
.put("COUNT").put(count);
return execute(cmd);
}

Expand All @@ -335,7 +331,7 @@ Uni<Response> _bzmpopMin(Duration timeout, K... keys) {
doesNotContainNull(keys, "keys");
validate(timeout, "timeout");

RedisCommand cmd = RedisCommand.of(BZMPOP).put(timeout.toSeconds())
RedisCommand cmd = RedisCommand.of(Command.BZMPOP).put(timeout.toSeconds())
.put(keys.length).putAll(marshaller.encode(keys)).put("MIN");
return execute(cmd);
}
Expand All @@ -345,7 +341,7 @@ Uni<Response> _bzmpopMin(Duration timeout, int count, K... keys) {
doesNotContainNull(keys, "keys");
validate(timeout, "timeout");

RedisCommand cmd = RedisCommand.of(BZMPOP).put(timeout.toSeconds())
RedisCommand cmd = RedisCommand.of(Command.BZMPOP).put(timeout.toSeconds())
.put(keys.length).putAll(marshaller.encode(keys)).put("MIN").put("COUNT").put(count);
return execute(cmd);
}
Expand All @@ -355,7 +351,7 @@ Uni<Response> _bzmpopMax(Duration timeout, K... keys) {
doesNotContainNull(keys, "keys");
validate(timeout, "timeout");

RedisCommand cmd = RedisCommand.of(BZMPOP).put(timeout.toSeconds())
RedisCommand cmd = RedisCommand.of(Command.BZMPOP).put(timeout.toSeconds())
.put(keys.length).putAll(marshaller.encode(keys)).put("MAX");
return execute(cmd);
}
Expand All @@ -365,7 +361,7 @@ Uni<Response> _bzmpopMax(Duration timeout, int count, K... keys) {
doesNotContainNull(keys, "keys");
validate(timeout, "timeout");

RedisCommand cmd = RedisCommand.of(BZMPOP).put(timeout.toSeconds())
RedisCommand cmd = RedisCommand.of(Command.BZMPOP).put(timeout.toSeconds())
.put(keys.length).putAll(marshaller.encode(keys)).put("MAX").put("COUNT").put(count);
return execute(cmd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class AbstractStringCommands<K, V> extends AbstractRedisCommands {

protected final Type typeOfValue;

public static final Command LCS = Command.create("lcs");

AbstractStringCommands(RedisCommandExecutor redis, Type k, Type v) {
super(redis, new Marshaller(k, v));
this.typeOfValue = v;
Expand Down Expand Up @@ -254,13 +252,13 @@ Uni<Response> _lcs(K key1, K key2) {
nonNull(key1, "key1");
nonNull(key2, "key2");

return execute(RedisCommand.of(LCS).put(marshaller.encode(key1)).put(marshaller.encode(key2)));
return execute(RedisCommand.of(Command.LCS).put(marshaller.encode(key1)).put(marshaller.encode(key2)));
}

Uni<Response> _lcsLength(K key1, K key2) {
nonNull(key1, "key1");
nonNull(key2, "key2");

return execute(RedisCommand.of(LCS).put(marshaller.encode(key1)).put(marshaller.encode(key2)).put("LEN"));
return execute(RedisCommand.of(Command.LCS).put(marshaller.encode(key1)).put(marshaller.encode(key2)).put("LEN"));
}
}
Loading

0 comments on commit d35d52f

Please sign in to comment.