/**
* Copyright 2015 Red Hat, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/
package io.vertx.redis.impl;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.RedisClient;
import io.vertx.redis.RedisOptions;
import io.vertx.redis.RedisTransaction;
import io.vertx.redis.Script;
import io.vertx.redis.op.*;
import java.util.*;
import java.util.stream.Stream;
import static io.vertx.redis.impl.RedisCommand.*;
public final class RedisClientImpl extends AbstractRedisClient {
private RedisTransaction transaction;
public RedisClientImpl(Vertx vertx, RedisOptions config) {
super(vertx, config);
this.transaction = new RedisTransactionImpl();
}
/**
* A helper method to package method parameters into JsonArray payload.
*
* Null parameters are ignored.
*
* @param parameters Call parameters
* @return JsonArray that can be passed to send()
*/
@SuppressWarnings("unchecked")
private static List> toPayload(Object... parameters) {
List result = new ArrayList<>(parameters.length);
for (Object param : parameters) {
// unwrap
if (param instanceof JsonArray) {
param = ((JsonArray) param).getList();
}
// unwrap
if (param instanceof JsonObject) {
param = ((JsonObject) param).getMap();
}
if (param instanceof Collection) {
((Collection) param).stream().filter(Objects::nonNull).forEach(result::add);
} else if (param instanceof Map) {
for (Map.Entry, ?> pair : ((Map, ?>) param).entrySet()) {
result.add(pair.getKey());
result.add(pair.getValue());
}
} else if (param instanceof Stream) {
((Stream) param).forEach(e -> {
if (e instanceof Object[]) {
Collections.addAll(result, (Object[]) e);
} else {
result.add(e);
}
});
} else if (param instanceof Buffer) {
result.add(((Buffer) param).getBytes());
} else if (param != null) {
result.add(param);
}
}
return result;
}
@Override
public RedisClient append(String key, String value, Handler> handler) {
sendLong(APPEND, toPayload(key, value), handler);
return this;
}
@Override
public RedisClient auth(String password, Handler> handler) {
sendString(AUTH, toPayload(password), handler);
return this;
}
@Override
public RedisClient bgrewriteaof(Handler> handler) {
sendString(BGREWRITEAOF, null, handler);
return this;
}
@Override
public RedisClient bgsave(Handler> handler) {
sendString(BGSAVE, null, handler);
return this;
}
@Override
public RedisClient bitcount(String key, Handler> handler) {
sendLong(BITCOUNT, toPayload(key), handler);
return this;
}
public RedisClient bitcountRange(String key, long start, long end, Handler> handler) {
sendLong(BITCOUNT, toPayload(key, start, end), handler);
return this;
}
@Override
public RedisClient bitop(BitOperation operation, String destkey, List keys, Handler> handler) {
sendLong(BITOP, toPayload(operation.name(), destkey, keys), handler);
return this;
}
@Override
public RedisClient bitpos(String key, int bit, Handler> handler) {
sendLong(BITPOS, toPayload(key, bit), handler);
return this;
}
@Override
public RedisClient bitposFrom(String key, int bit, int start, Handler> handler) {
sendLong(BITPOS, toPayload(key, bit, start), handler);
return this;
}
@Override
public RedisClient bitposRange(String key, int bit, int start, int stop, Handler> handler) {
sendLong(BITPOS, toPayload(key, bit, start, stop), handler);
return this;
}
@Override
public RedisClient blpop(String key, int seconds, Handler> handler) {
sendJsonArray(BLPOP, toPayload(key, seconds), handler);
return this;
}
@Override
public RedisClient blpopMany(List keys, int seconds, Handler> handler) {
sendJsonArray(BLPOP, toPayload(keys, seconds), handler);
return this;
}
@Override
public RedisClient brpop(String key, int seconds, Handler> handler) {
sendJsonArray(BRPOP, toPayload(key, seconds), handler);
return this;
}
@Override
public RedisClient brpopMany(List keys, int seconds, Handler> handler) {
sendJsonArray(BRPOP, toPayload(keys, seconds), handler);
return this;
}
@Override
public RedisClient brpoplpush(String key, String destkey, int seconds, Handler> handler) {
sendString(BRPOPLPUSH, toPayload(key, destkey, seconds), handler);
return this;
}
@Override
public RedisClient clientKill(KillFilter filter, Handler> handler) {
sendLong(CLIENT_KILL, filter.toJsonArray().getList(), handler);
return this;
}
@Override
public RedisClient clientList(Handler> handler) {
sendString(CLIENT_LIST, null, handler);
return this;
}
@Override
public RedisClient clientGetname(Handler> handler) {
sendString(CLIENT_GETNAME, null, handler);
return this;
}
@Override
public RedisClient clientPause(long millis, Handler> handler) {
sendString(CLIENT_PAUSE, toPayload(millis), handler);
return this;
}
@Override
public RedisClient clientSetname(String name, Handler> handler) {
sendString(CLIENT_SETNAME, toPayload(name), handler);
return this;
}
@Override
public RedisClient clusterAddslots(List slots, Handler> handler) {
sendVoid(CLUSTER_ADDSLOTS, null, handler);
return this;
}
@Override
public RedisClient clusterCountFailureReports(String nodeId, Handler> handler) {
sendLong(CLUSTER_COUNT_FAILURE_REPORTS, toPayload(nodeId), handler);
return this;
}
@Override
public RedisClient clusterCountkeysinslot(long slot, Handler> handler) {
sendLong(CLUSTER_COUNTKEYSINSLOT, toPayload(slot), handler);
return this;
}
@Override
public RedisClient clusterDelslots(long slot, Handler> handler) {
sendVoid(CLUSTER_DELSLOTS, toPayload(slot), handler);
return this;
}
@Override
public RedisClient clusterDelslotsMany(List slots, Handler> handler) {
sendVoid(CLUSTER_DELSLOTS, toPayload(slots), handler);
return this;
}
@Override
public RedisClient clusterFailover(Handler> handler) {
sendVoid(CLUSTER_FAILOVER, null, handler);
return this;
}
@Override
public RedisClient clusterFailOverWithOptions(FailoverOptions options, Handler> handler) {
sendVoid(CLUSTER_FAILOVER, toPayload(options), handler);
return this;
}
@Override
public RedisClient clusterForget(String nodeId, Handler> handler) {
sendVoid(CLUSTER_FORGET, toPayload(nodeId), handler);
return this;
}
@Override
public RedisClient clusterGetkeysinslot(long slot, long count, Handler> handler) {
sendJsonArray(CLUSTER_GETKEYSINSLOT, toPayload(slot, count), handler);
return this;
}
@Override
public RedisClient clusterInfo(Handler> handler) {
sendJsonArray(CLUSTER_INFO, null, handler);
return this;
}
@Override
public RedisClient clusterKeyslot(String key, Handler> handler) {
sendLong(CLUSTER_KEYSLOT, toPayload(key), handler);
return this;
}
@Override
public RedisClient clusterMeet(String ip, long port, Handler> handler) {
sendVoid(CLUSTER_MEET, toPayload(ip, port), handler);
return this;
}
@Override
public RedisClient clusterNodes(Handler> handler) {
sendJsonArray(CLUSTER_NODES, null, handler);
return this;
}
@Override
public RedisClient clusterReplicate(String nodeId, Handler> handler) {
sendVoid(CLUSTER_REPLICATE, toPayload(nodeId), handler);
return this;
}
@Override
public RedisClient clusterReset(Handler> handler) {
sendVoid(CLUSTER_RESET, null, handler);
return this;
}
@Override
public RedisClient clusterResetWithOptions(ResetOptions options, Handler> handler) {
sendVoid(CLUSTER_RESET, toPayload(options), handler);
return this;
}
@Override
public RedisClient clusterSaveconfig(Handler> handler) {
sendVoid(CLUSTER_SAVECONFIG, null, handler);
return this;
}
@Override
public RedisClient clusterSetConfigEpoch(long epoch, Handler> handler) {
sendVoid(CLUSTER_SET_CONFIG_EPOCH, toPayload(epoch), handler);
return this;
}
@Override
public RedisClient clusterSetslot(long slot, SlotCmd subcommand, Handler> handler) {
sendVoid(CLUSTER_SETSLOT, toPayload(slot, subcommand), handler);
return this;
}
@Override
public RedisClient clusterSetslotWithNode(long slot, SlotCmd subcommand, String nodeId, Handler> handler) {
sendVoid(CLUSTER_SETSLOT, toPayload(slot, subcommand, nodeId), handler);
return this;
}
@Override
public RedisClient clusterSlaves(String nodeId, Handler> handler) {
sendJsonArray(CLUSTER_SLAVES, toPayload(nodeId), handler);
return this;
}
@Override
public RedisClient clusterSlots(Handler> handler) {
sendJsonArray(CLUSTER_SLOTS, null, handler);
return this;
}
@Override
public RedisClient command(Handler> handler) {
sendJsonArray(COMMAND, null, handler);
return this;
}
@Override
public RedisClient commandCount(Handler> handler) {
sendLong(COMMAND_COUNT, null, handler);
return this;
}
@Override
public RedisClient commandGetkeys(Handler> handler) {
sendJsonArray(COMMAND_GETKEYS, null, handler);
return this;
}
@Override
public RedisClient commandInfo(List commands, Handler> handler) {
sendJsonArray(COMMAND_INFO, toPayload(commands), handler);
return this;
}
@Override
public RedisClient configGet(String parameter, Handler> handler) {
sendJsonArray(CONFIG_GET, toPayload(parameter), handler);
return this;
}
@Override
public RedisClient configRewrite(Handler> handler) {
sendString(CONFIG_REWRITE, null, handler);
return this;
}
@Override
public RedisClient configSet(String parameter, String value, Handler> handler) {
sendString(CONFIG_SET, toPayload(parameter, value), handler);
return this;
}
@Override
public RedisClient configResetstat(Handler> handler) {
sendString(CONFIG_RESETSTAT, null, handler);
return this;
}
@Override
public RedisClient dbsize(Handler> handler) {
sendLong(DBSIZE, null, handler);
return this;
}
@Override
public RedisClient debugObject(String key, Handler> handler) {
sendString(DEBUG_OBJECT, toPayload(key), handler);
return this;
}
@Override
public RedisClient debugSegfault(Handler> handler) {
sendString(DEBUG_SEGFAULT, null, handler);
return this;
}
@Override
public RedisClient decr(String key, Handler> handler) {
sendLong(DECR, toPayload(key), handler);
return this;
}
@Override
public RedisClient decrby(String key, long decrement, Handler> handler) {
sendLong(DECRBY, toPayload(key, decrement), handler);
return this;
}
@Override
public RedisClient del(String key, Handler> handler) {
sendLong(DEL, toPayload(key), handler);
return this;
}
@Override
public RedisClient delMany(List keys, Handler> handler) {
sendLong(DEL, toPayload(keys), handler);
return this;
}
@Override
public RedisClient dump(String key, Handler> handler) {
send(DUMP, toPayload(key), String.class, true, dump -> {
if (dump.failed()) {
handler.handle(dump);
} else {
handler.handle(Future.succeededFuture(RedisEncoding.encode(dump.result())));
}
});
return this;
}
@Override
public RedisClient echo(String message, Handler> handler) {
sendString(ECHO, toPayload(message), handler);
return this;
}
@Override
public RedisClient eval(String script, List keys, List args, Handler> handler) {
keys = (keys != null) ? keys : Collections.emptyList();
args = (args != null) ? args : Collections.emptyList();
sendJsonArray(EVAL, toPayload(script, keys.size(), keys, args), handler);
return this;
}
@Override
public RedisClient evalsha(String sha1, List keys, List args, Handler> handler) {
keys = (keys != null) ? keys : Collections.emptyList();
args = (args != null) ? args : Collections.emptyList();
sendJsonArray(EVALSHA, toPayload(sha1, keys.size(), keys, args), handler);
return this;
}
@Override
public RedisClient evalScript(Script script, List keys, List args, Handler> handler) {
this.evalsha(script.getSha1(), keys, args, res -> {
if (res.failed() && res.cause().getMessage().startsWith("NOSCRIPT")) {
this.eval(script.getScript(), keys, args, handler);
} else {
handler.handle(res);
}
});
return this;
}
@Override
public RedisClient exists(String key, Handler> handler) {
sendLong(EXISTS, toPayload(key), handler);
return this;
}
@Override
public RedisClient existsMany(List keys, Handler> handler) {
sendLong(EXISTS, toPayload(keys), handler);
return this;
}
@Override
public RedisClient expire(String key, long seconds, Handler> handler) {
sendLong(EXPIRE, toPayload(key, seconds), handler);
return this;
}
@Override
public RedisClient expireat(String key, long seconds, Handler> handler) {
sendLong(EXPIREAT, toPayload(key, seconds), handler);
return this;
}
@Override
public RedisClient flushall(Handler> handler) {
sendString(FLUSHALL, null, handler);
return this;
}
@Override
public RedisClient flushdb(Handler> handler) {
sendString(FLUSHDB, null, handler);
return this;
}
@Override
public RedisClient get(String key, Handler> handler) {
sendString(GET, toPayload(key), handler);
return this;
}
@Override
public RedisClient getBinary(String key, Handler> handler) {
send(GET, toPayload(key), Buffer.class, true, handler);
return this;
}
@Override
public RedisClient getbit(String key, long offset, Handler> handler) {
sendLong(GETBIT, toPayload(key, offset), handler);
return this;
}
@Override
public RedisClient getrange(String key, long start, long end, Handler> handler) {
sendString(GETRANGE, toPayload(key, start, end), handler);
return this;
}
@Override
public RedisClient getset(String key, String value, Handler> handler) {
sendString(GETSET, toPayload(key, value), handler);
return this;
}
@Override
public RedisClient hdel(String key, String field, Handler> handler) {
sendLong(HDEL, toPayload(key, field), handler);
return this;
}
@Override
public RedisClient hdelMany(String key, List fields, Handler> handler) {
sendLong(HDEL, toPayload(key, fields), handler);
return this;
}
@Override
public RedisClient hexists(String key, String field, Handler> handler) {
sendLong(HEXISTS, toPayload(key, field), handler);
return this;
}
@Override
public RedisClient hget(String key, String field, Handler> handler) {
sendString(HGET, toPayload(key, field), handler);
return this;
}
@Override
public RedisClient hgetall(String key, Handler> handler) {
sendJsonObject(HGETALL, toPayload(key), handler);
return this;
}
@Override
public RedisClient hincrby(String key, String field, long increment, Handler> handler) {
sendLong(HINCRBY, toPayload(key, field, increment), handler);
return this;
}
@Override
public RedisClient hincrbyfloat(String key, String field, double increment, Handler> handler) {
sendString(HINCRBYFLOAT, toPayload(key, field, increment), handler);
return this;
}
@Override
public RedisClient hkeys(String key, Handler> handler) {
sendJsonArray(HKEYS, toPayload(key), handler);
return this;
}
@Override
public RedisClient hlen(String key, Handler> handler) {
sendLong(HLEN, toPayload(key), handler);
return this;
}
@Override
public RedisClient hmget(String key, List fields, Handler> handler) {
sendJsonArray(HMGET, toPayload(key, fields), handler);
return this;
}
@Override
public RedisClient hmset(String key, JsonObject values, Handler> handler) {
sendString(HMSET, toPayload(key, values), handler);
return this;
}
@Override
public RedisClient hset(String key, String field, String value, Handler> handler) {
sendLong(HSET, toPayload(key, field, value), handler);
return this;
}
@Override
public RedisClient hsetnx(String key, String field, String value, Handler> handler) {
sendLong(HSETNX, toPayload(key, field, value), handler);
return this;
}
@Override
public RedisClient hvals(String key, Handler> handler) {
sendJsonArray(HVALS, toPayload(key), handler);
return this;
}
@Override
public RedisClient incr(String key, Handler> handler) {
sendLong(INCR, toPayload(key), handler);
return this;
}
@Override
public RedisClient incrby(String key, long increment, Handler> handler) {
sendLong(INCRBY, toPayload(key, increment), handler);
return this;
}
@Override
public RedisClient incrbyfloat(String key, double increment, Handler> handler) {
sendString(INCRBYFLOAT, toPayload(key, increment), handler);
return this;
}
@Override
public RedisClient info(Handler> handler) {
sendJsonObject(INFO, Collections.emptyList(), handler);
return this;
}
@Override
public RedisClient infoSection(String section, Handler> handler) {
sendJsonObject(INFO, toPayload(section), handler);
return this;
}
@Override
public RedisClient keys(String pattern, Handler> handler) {
sendJsonArray(KEYS, toPayload(pattern), handler);
return this;
}
@Override
public RedisClient lastsave(Handler> handler) {
sendLong(LASTSAVE, null, handler);
return this;
}
@Override
public RedisClient lindex(String key, int index, Handler> handler) {
sendString(LINDEX, toPayload(key, index), handler);
return this;
}
@Override
public RedisClient linsert(String key, InsertOptions option, String pivot, String value, Handler> handler) {
sendLong(LINSERT, toPayload(key, option.name(), pivot, value), handler);
return this;
}
@Override
public RedisClient llen(String key, Handler> handler) {
sendLong(LLEN, toPayload(key), handler);
return this;
}
@Override
public RedisClient lpop(String key, Handler> handler) {
sendString(LPOP, toPayload(key), handler);
return this;
}
@Override
public RedisClient lpushMany(String key, List values, Handler> handler) {
sendLong(LPUSH, toPayload(key, values), handler);
return this;
}
@Override
public RedisClient lpush(String key, String value, Handler> handler) {
sendLong(LPUSH, toPayload(key, value), handler);
return this;
}
@Override
public RedisClient lpushx(String key, String value, Handler> handler) {
sendLong(LPUSHX, toPayload(key, value), handler);
return this;
}
@Override
public RedisClient lrange(String key, long from, long to, Handler> handler) {
sendJsonArray(LRANGE, toPayload(key, from, to), handler);
return this;
}
@Override
public RedisClient lrem(String key, long count, String value, Handler> handler) {
sendLong(LREM, toPayload(key, count, value), handler);
return this;
}
@Override
public RedisClient lset(String key, long index, String value, Handler> handler) {
sendString(LSET, toPayload(key, index, value), handler);
return this;
}
@Override
public RedisClient ltrim(String key, long from, long to, Handler> handler) {
sendString(LTRIM, toPayload(key, from, to), handler);
return this;
}
@Override
public RedisClient mget(String key, Handler> handler) {
sendJsonArray(MGET, toPayload(key), handler);
return this;
}
@Override
public RedisClient mgetMany(List keys, Handler> handler) {
sendJsonArray(MGET, toPayload(keys), handler);
return this;
}
@Override
public RedisClient migrate(String host, int port, String key, int destdb, long timeout, MigrateOptions options, Handler> handler) {
sendString(MIGRATE, toPayload(host, port, key, destdb, timeout, options != null ? options.toJsonArray() : null), handler);
return this;
}
@Override
public RedisClient monitor(Handler> handler) {
sendVoid(MONITOR, null, handler);
return this;
}
@Override
public RedisClient move(String key, int destdb, Handler> handler) {
sendLong(MOVE, toPayload(key, destdb), handler);
return this;
}
@Override
public RedisClient mset(JsonObject keyvals, Handler> handler) {
sendString(MSET, toPayload(keyvals), handler);
return this;
}
@Override
public RedisClient msetnx(JsonObject keyvals, Handler> handler) {
sendLong(MSETNX, toPayload(keyvals), handler);
return this;
}
@Override
public RedisClient object(String key, ObjectCmd cmd, Handler> handler) {
sendVoid(OBJECT, toPayload(cmd.name(), key), handler);
return this;
}
@Override
public RedisClient persist(String key, Handler> handler) {
sendLong(PERSIST, toPayload(key), handler);
return this;
}
@Override
public RedisClient pexpire(String key, long millis, Handler> handler) {
sendLong(PEXPIRE, toPayload(key, millis), handler);
return this;
}
@Override
public RedisClient pexpireat(String key, long millis, Handler> handler) {
sendLong(PEXPIREAT, toPayload(key, millis), handler);
return this;
}
@Override
public RedisClient pfadd(String key, String element, Handler> handler) {
sendLong(PFADD, toPayload(key, element), handler);
return this;
}
@Override
public RedisClient pfaddMany(String key, List elements, Handler> handler) {
sendLong(PFADD, toPayload(key, elements), handler);
return this;
}
@Override
public RedisClient pfcount(String key, Handler> handler) {
sendLong(PFCOUNT, toPayload(key), handler);
return this;
}
@Override
public RedisClient pfcountMany(List key, Handler> handler) {
sendLong(PFCOUNT, toPayload(key), handler);
return this;
}
@Override
public RedisClient pfmerge(String destkey, List keys, Handler> handler) {
sendString(PFMERGE, toPayload(destkey, keys), handler);
return this;
}
@Override
public RedisClient ping(Handler> handler) {
sendString(PING, null, handler);
return this;
}
@Override
public RedisClient psetex(String key, long millis, String value, Handler> handler) {
sendVoid(PSETEX, toPayload(key, millis, value), handler);
return this;
}
@Override
public RedisClient psubscribe(String pattern, Handler> handler) {
sendJsonArray(PSUBSCRIBE, toPayload(pattern), handler);
return this;
}
@Override
public RedisClient psubscribeMany(List patterns, Handler> handler) {
sendJsonArray(PSUBSCRIBE, toPayload(patterns), handler);
return this;
}
@Override
public RedisClient pubsubChannels(String pattern, Handler> handler) {
sendJsonArray(PUBSUB, toPayload("CHANNELS", pattern == null || "".equals(pattern) ? null : pattern), handler);
return this;
}
public RedisClient pubsubNumsub(List channels, Handler> handler) {
sendJsonArray(PUBSUB, toPayload("NUMSUB", channels), handler);
return this;
}
public RedisClient pubsubNumpat(Handler> handler) {
sendLong(PUBSUB, toPayload("NUMPAT"), handler);
return this;
}
@Override
public RedisClient pttl(String key, Handler> handler) {
sendLong(PTTL, toPayload(key), handler);
return this;
}
@Override
public RedisClient publish(String channel, String message, Handler> handler) {
sendLong(PUBLISH, toPayload(channel, message), handler);
return this;
}
@Override
public RedisClient punsubscribe(List patterns, Handler> handler) {
sendVoid(PUNSUBSCRIBE, toPayload(patterns), handler);
return this;
}
@Override
public RedisClient randomkey(Handler> handler) {
sendString(RANDOMKEY, null, handler);
return this;
}
@Override
public RedisClient rename(String key, String newkey, Handler> handler) {
sendString(RENAME, toPayload(key, newkey), handler);
return this;
}
@Override
public RedisClient renamenx(String key, String newkey, Handler> handler) {
sendLong(RENAMENX, toPayload(key, newkey), handler);
return this;
}
@Override
public RedisClient restore(String key, long millis, String serialized, Handler> handler) {
send(RESTORE, toPayload(key, millis, RedisEncoding.decode(serialized)), String.class, true, handler);
return this;
}
@Override
public RedisClient role(Handler> handler) {
sendJsonArray(ROLE, null, handler);
return this;
}
@Override
public RedisClient rpop(String key, Handler> handler) {
sendString(RPOP, toPayload(key), handler);
return this;
}
@Override
public RedisClient rpoplpush(String key, String destkey, Handler> handler) {
sendString(RPOPLPUSH, toPayload(key, destkey), handler);
return this;
}
@Override
public RedisClient rpushMany(String key, List values, Handler> handler) {
sendLong(RPUSH, toPayload(key, values), handler);
return this;
}
@Override
public RedisClient rpush(String key, String value, Handler> handler) {
sendLong(RPUSH, toPayload(key, value), handler);
return this;
}
@Override
public RedisClient rpushx(String key, String value, Handler> handler) {
sendLong(RPUSHX, toPayload(key, value), handler);
return this;
}
@Override
public RedisClient sadd(String key, String member, Handler> handler) {
sendLong(SADD, toPayload(key, member), handler);
return this;
}
@Override
public RedisClient saddMany(String key, List members, Handler> handler) {
sendLong(SADD, toPayload(key, members), handler);
return this;
}
@Override
public RedisClient save(Handler> handler) {
sendString(SAVE, null, handler);
return this;
}
@Override
public RedisClient scard(String key, Handler> handler) {
sendLong(SCARD, toPayload(key), handler);
return this;
}
@Override
public RedisClient scriptExists(String script, Handler> handler) {
sendJsonArray(SCRIPT_EXISTS, toPayload(script), handler);
return this;
}
@Override
public RedisClient scriptExistsMany(List scripts, Handler> handler) {
sendJsonArray(SCRIPT_EXISTS, toPayload(scripts), handler);
return this;
}
@Override
public RedisClient scriptFlush(Handler> handler) {
sendString(SCRIPT_FLUSH, null, handler);
return this;
}
@Override
public RedisClient scriptKill(Handler> handler) {
sendString(SCRIPT_KILL, null, handler);
return this;
}
@Override
public RedisClient scriptLoad(String script, Handler> handler) {
sendString(SCRIPT_LOAD, toPayload(script), handler);
return this;
}
@Override
public RedisClient sdiff(String key, List cmpkeys, Handler> handler) {
sendJsonArray(SDIFF, toPayload(key, cmpkeys), handler);
return this;
}
@Override
public RedisClient sdiffstore(String destkey, String key, List cmpkeys, Handler> handler) {
sendLong(SDIFFSTORE, toPayload(destkey, key, cmpkeys), handler);
return this;
}
@Override
public RedisClient select(int dbindex, Handler> handler) {
sendString(SELECT, toPayload(dbindex), handler);
return this;
}
@Override
public RedisClient select(String dbindex, Handler> handler) {
sendString(SELECT, toPayload(dbindex), handler);
return this;
}
@Override
public RedisClient set(String key, String value, Handler> handler) {
sendVoid(SET, toPayload(key, value), handler);
return this;
}
@Override
public RedisClient setWithOptions(String key, String value, SetOptions options, Handler> handler) {
sendString(SET, toPayload(key, value, options != null ? options.toJsonArray() : null), handler);
return this;
}
@Override
public RedisClient setBinary(String key, Buffer value, Handler> handler) {
send(SET, toPayload(key, value), Void.class, true, handler);
return this;
}
@Override
public RedisClient setBinaryWithOptions(String key, Buffer value, SetOptions options, Handler> handler) {
send(SET, toPayload(key, value, options != null ? options.toJsonArray() : null), Void.class, true, handler);
return this;
}
@Override
public RedisClient setbit(String key, long offset, int bit, Handler> handler) {
sendLong(SETBIT, toPayload(key, offset, bit), handler);
return this;
}
@Override
public RedisClient setex(String key, long seconds, String value, Handler> handler) {
sendString(SETEX, toPayload(key, seconds, value), handler);
return this;
}
@Override
public RedisClient setnx(String key, String value, Handler> handler) {
sendLong(SETNX, toPayload(key, value), handler);
return this;
}
@Override
public RedisClient setrange(String key, int offset, String value, Handler> handler) {
sendLong(SETRANGE, toPayload(key, offset, value), handler);
return this;
}
@Override
public RedisClient sinter(List keys, Handler> handler) {
sendJsonArray(SINTER, toPayload(keys), handler);
return this;
}
@Override
public RedisClient sinterstore(String destkey, List keys, Handler> handler) {
sendLong(SINTERSTORE, toPayload(destkey, keys), handler);
return this;
}
@Override
public RedisClient sismember(String key, String member, Handler> handler) {
sendLong(SISMEMBER, toPayload(key, member), handler);
return this;
}
@Override
public RedisClient slaveof(String host, int port, Handler> handler) {
sendString(SLAVEOF, toPayload(host, port), handler);
return this;
}
@Override
public RedisClient slaveofNoone(Handler> handler) {
sendString(SLAVEOF, toPayload("NO", "ONE"), handler);
return this;
}
@Override
public RedisClient slowlogGet(int limit, Handler> handler) {
sendJsonArray(SLOWLOG, toPayload("GET", limit < 0 ? null : limit), handler);
return this;
}
@Override
public RedisClient slowlogLen(Handler> handler) {
sendLong(SLOWLOG, toPayload("LEN"), handler);
return this;
}
@Override
public RedisClient slowlogReset(Handler> handler) {
sendVoid(SLOWLOG, toPayload("RESET"), handler);
return this;
}
@Override
public RedisClient smembers(String key, Handler> handler) {
sendJsonArray(SMEMBERS, toPayload(key), handler);
return this;
}
@Override
public RedisClient smove(String key, String destkey, String member, Handler> handler) {
sendLong(SMOVE, toPayload(key, destkey, member), handler);
return this;
}
@Override
public RedisClient sort(String key, SortOptions options, Handler> handler) {
sendJsonArray(SORT, toPayload(key, options != null ? options.toJsonArray() : null), handler);
return this;
}
@Override
public RedisClient spop(String key, Handler> handler) {
sendString(SPOP, toPayload(key), handler);
return this;
}
@Override
public RedisClient spopMany(String key, int count, Handler> handler) {
sendJsonArray(SPOP, toPayload(key, count), handler);
return this;
}
@Override
public RedisClient srandmember(String key, Handler> handler) {
sendString(SRANDMEMBER, toPayload(key), handler);
return this;
}
@Override
public RedisClient srandmemberCount(String key, int count, Handler> handler) {
sendJsonArray(SRANDMEMBER, toPayload(key, count), handler);
return this;
}
@Override
public RedisClient srem(String key, String member, Handler> handler) {
sendLong(SREM, toPayload(key, member), handler);
return this;
}
@Override
public RedisClient sremMany(String key, List members, Handler> handler) {
sendLong(SREM, toPayload(key, members), handler);
return this;
}
@Override
public RedisClient strlen(String key, Handler> handler) {
sendLong(STRLEN, toPayload(key), handler);
return this;
}
@Override
public RedisClient subscribe(String channel, Handler> handler) {
sendJsonArray(SUBSCRIBE, toPayload(channel), handler);
return this;
}
@Override
public RedisClient subscribeMany(List channels, Handler> handler) {
sendJsonArray(SUBSCRIBE, toPayload(channels), handler);
return this;
}
@Override
public RedisClient sunion(List keys, Handler> handler) {
sendJsonArray(SUNION, toPayload(keys), handler);
return this;
}
@Override
public RedisClient sunionstore(String destkey, List keys, Handler> handler) {
sendLong(SUNIONSTORE, toPayload(destkey, keys), handler);
return this;
}
@Override
public RedisClient sync(Handler> handler) {
sendVoid(SYNC, null, handler);
return this;
}
@Override
public RedisClient time(Handler> handler) {
sendJsonArray(TIME, null, handler);
return this;
}
@Override
public RedisTransaction transaction() {
return transaction;
}
@Override
public RedisClient ttl(String key, Handler> handler) {
sendLong(TTL, toPayload(key), handler);
return this;
}
@Override
public RedisClient type(String key, Handler> handler) {
sendString(TYPE, toPayload(key), handler);
return this;
}
@Override
public RedisClient unsubscribe(List channels, Handler> handler) {
sendVoid(UNSUBSCRIBE, toPayload(channels), handler);
return this;
}
@Override
public RedisClient wait(long numSlaves, long timeout, Handler> handler) {
sendString(WAIT, toPayload(numSlaves, timeout), handler);
return this;
}
@Override
public RedisClient zadd(String key, double score, String member, Handler> handler) {
sendLong(ZADD, toPayload(key, score, member), handler);
return this;
}
@Override
public RedisClient zaddMany(String key, Map members, Handler> handler) {
// flip from to when wrapping
Stream flipped = members.entrySet().stream().map(e -> new Object[]{e.getValue(), e.getKey()});
sendLong(ZADD, toPayload(key, flipped), handler);
return this;
}
@Override
public RedisClient zcard(String key, Handler> handler) {
sendLong(ZCARD, toPayload(key), handler);
return this;
}
@Override
public RedisClient zcount(String key, double min, double max, Handler> handler) {
String minVal = (min == Double.NEGATIVE_INFINITY) ? "-inf" : String.valueOf(min);
String maxVal = (max == Double.POSITIVE_INFINITY) ? "+inf" : String.valueOf(max);
sendLong(ZCOUNT, toPayload(key, minVal, maxVal), handler);
return this;
}
@Override
public RedisClient zincrby(String key, double increment, String member, Handler> handler) {
sendString(ZINCRBY, toPayload(key, increment, member), handler);
return this;
}
@Override
public RedisClient zinterstore(String destkey, List sets, AggregateOptions options, Handler> handler) {
sendLong(ZINTERSTORE, toPayload(destkey, sets.size(), sets, options != null ? options.name() : null), handler);
return this;
}
@Override
public RedisClient zinterstoreWeighed(String destkey, Map sets, AggregateOptions options, Handler> handler) {
sendLong(ZINTERSTORE, toPayload(destkey, sets.size(), sets.keySet(), "WEIGHTS", sets.values(),
options != null ? options.toJsonArray() : null), handler);
return this;
}
@Override
public RedisClient zlexcount(String key, String min, String max, Handler> handler) {
sendLong(ZLEXCOUNT, toPayload(key, min, max), handler);
return this;
}
@Override
public RedisClient zrange(String key, long start, long stop, Handler> handler) {
sendJsonArray(ZRANGE, toPayload(key, start, stop), handler);
return this;
}
@Override
public RedisClient zrangeWithOptions(String key, long start, long stop, RangeOptions options, Handler> handler) {
sendJsonArray(ZRANGE, toPayload(key, start, stop, options != null ? options.toJsonArray() : null), handler);
return this;
}
@Override
public RedisClient zrangebylex(String key, String min, String max, LimitOptions options, Handler> handler) {
sendJsonArray(ZRANGEBYLEX, toPayload(key, min, max, options != null ? options.toJsonArray() : null), handler);
return this;
}
@Override
public RedisClient zrangebyscore(String key, String min, String max, RangeLimitOptions options, Handler> handler) {
sendJsonArray(ZRANGEBYSCORE, toPayload(key, min, max, options != null ? options.toJsonArray() : null), handler);
return this;
}
@Override
public RedisClient zrank(String key, String member, Handler> handler) {
sendLong(ZRANK, toPayload(key, member), handler);
return this;
}
@Override
public RedisClient zrem(String key, String member, Handler> handler) {
sendLong(ZREM, toPayload(key, member), handler);
return this;
}
@Override
public RedisClient zremMany(String key, List members, Handler> handler) {
sendLong(ZREM, toPayload(key, members), handler);
return this;
}
@Override
public RedisClient zremrangebylex(String key, String min, String max, Handler> handler) {
sendLong(ZREMRANGEBYLEX, toPayload(key, min, max), handler);
return this;
}
@Override
public RedisClient zremrangebyrank(String key, long start, long stop, Handler