redis.clients.jedis.CommandObjects Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jedis Show documentation
Show all versions of jedis Show documentation
Jedis is a blazingly small and sane Redis java client.
package redis.clients.jedis;
import static redis.clients.jedis.Protocol.Command.*;
import static redis.clients.jedis.Protocol.Keyword.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.json.JSONArray;
import org.json.JSONObject;
import redis.clients.jedis.Protocol.Command;
import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.args.*;
import redis.clients.jedis.bloom.*;
import redis.clients.jedis.bloom.RedisBloomProtocol.*;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.gears.*;
import redis.clients.jedis.gears.RedisGearsProtocol.*;
import redis.clients.jedis.gears.resps.GearsLibraryInfo;
import redis.clients.jedis.graph.GraphProtocol.*;
import redis.clients.jedis.json.*;
import redis.clients.jedis.json.JsonProtocol.JsonCommand;
import redis.clients.jedis.json.DefaultGsonObjectMapper;
import redis.clients.jedis.json.JsonObjectMapper;
import redis.clients.jedis.params.*;
import redis.clients.jedis.resps.*;
import redis.clients.jedis.search.*;
import redis.clients.jedis.search.SearchProtocol.*;
import redis.clients.jedis.search.SearchResult.SearchResultBuilder;
import redis.clients.jedis.search.aggr.AggregationBuilder;
import redis.clients.jedis.search.aggr.AggregationResult;
import redis.clients.jedis.search.schemafields.SchemaField;
import redis.clients.jedis.timeseries.*;
import redis.clients.jedis.timeseries.TimeSeriesProtocol.*;
import redis.clients.jedis.util.KeyValue;
public class CommandObjects {
private RedisProtocol protocol;
// TODO: restrict?
public final void setProtocol(RedisProtocol proto) {
this.protocol = proto;
}
// TODO: remove?
protected RedisProtocol getProtocol() {
return protocol;
}
private volatile JsonObjectMapper jsonObjectMapper;
private final AtomicInteger searchDialect = new AtomicInteger(0);
private JedisBroadcastAndRoundRobinConfig broadcastAndRoundRobinConfig = null;
void setBroadcastAndRoundRobinConfig(JedisBroadcastAndRoundRobinConfig config) {
this.broadcastAndRoundRobinConfig = config;
}
protected CommandArguments commandArguments(ProtocolCommand command) {
return new CommandArguments(command);
}
private final CommandObject PING_COMMAND_OBJECT = new CommandObject<>(commandArguments(PING), BuilderFactory.STRING);
public final CommandObject ping() {
return PING_COMMAND_OBJECT;
}
private final CommandObject FLUSHALL_COMMAND_OBJECT = new CommandObject<>(commandArguments(FLUSHALL), BuilderFactory.STRING);
public final CommandObject flushAll() {
return FLUSHALL_COMMAND_OBJECT;
}
private final CommandObject FLUSHDB_COMMAND_OBJECT = new CommandObject<>(commandArguments(FLUSHDB), BuilderFactory.STRING);
public final CommandObject flushDB() {
return FLUSHDB_COMMAND_OBJECT;
}
public final CommandObject configSet(String parameter, String value) {
return new CommandObject<>(commandArguments(Command.CONFIG).add(Keyword.SET).add(parameter).add(value), BuilderFactory.STRING);
}
// Key commands
public final CommandObject exists(String key) {
return new CommandObject<>(commandArguments(Command.EXISTS).key(key), BuilderFactory.BOOLEAN);
}
public final CommandObject exists(String... keys) {
return new CommandObject<>(commandArguments(Command.EXISTS).keys((Object[]) keys), BuilderFactory.LONG);
}
public final CommandObject exists(byte[] key) {
return new CommandObject<>(commandArguments(Command.EXISTS).key(key), BuilderFactory.BOOLEAN);
}
public final CommandObject exists(byte[]... keys) {
return new CommandObject<>(commandArguments(Command.EXISTS).keys((Object[]) keys), BuilderFactory.LONG);
}
public final CommandObject persist(String key) {
return new CommandObject<>(commandArguments(Command.PERSIST).key(key), BuilderFactory.LONG);
}
public final CommandObject persist(byte[] key) {
return new CommandObject<>(commandArguments(Command.PERSIST).key(key), BuilderFactory.LONG);
}
public final CommandObject type(String key) {
return new CommandObject<>(commandArguments(Command.TYPE).key(key), BuilderFactory.STRING);
}
public final CommandObject type(byte[] key) {
return new CommandObject<>(commandArguments(Command.TYPE).key(key), BuilderFactory.STRING);
}
public final CommandObject dump(String key) {
return new CommandObject<>(commandArguments(Command.DUMP).key(key), BuilderFactory.BINARY);
}
public final CommandObject dump(byte[] key) {
return new CommandObject<>(commandArguments(Command.DUMP).key(key), BuilderFactory.BINARY);
}
public final CommandObject restore(String key, long ttl, byte[] serializedValue) {
return new CommandObject<>(commandArguments(RESTORE).key(key).add(ttl)
.add(serializedValue), BuilderFactory.STRING);
}
public final CommandObject restore(String key, long ttl, byte[] serializedValue, RestoreParams params) {
return new CommandObject<>(commandArguments(RESTORE).key(key).add(ttl)
.add(serializedValue).addParams(params), BuilderFactory.STRING);
}
public final CommandObject restore(byte[] key, long ttl, byte[] serializedValue) {
return new CommandObject<>(commandArguments(RESTORE).key(key).add(ttl)
.add(serializedValue), BuilderFactory.STRING);
}
public final CommandObject restore(byte[] key, long ttl, byte[] serializedValue, RestoreParams params) {
return new CommandObject<>(commandArguments(RESTORE).key(key).add(ttl)
.add(serializedValue).addParams(params), BuilderFactory.STRING);
}
public final CommandObject expire(String key, long seconds) {
return new CommandObject<>(commandArguments(EXPIRE).key(key).add(seconds), BuilderFactory.LONG);
}
public final CommandObject expire(byte[] key, long seconds) {
return new CommandObject<>(commandArguments(EXPIRE).key(key).add(seconds), BuilderFactory.LONG);
}
public final CommandObject expire(String key, long seconds, ExpiryOption expiryOption) {
return new CommandObject<>(commandArguments(EXPIRE).key(key).add(seconds).add(expiryOption),
BuilderFactory.LONG);
}
public final CommandObject expire(byte[] key, long seconds, ExpiryOption expiryOption) {
return new CommandObject<>(commandArguments(EXPIRE).key(key).add(seconds).add(expiryOption),
BuilderFactory.LONG);
}
public final CommandObject pexpire(String key, long milliseconds) {
return new CommandObject<>(commandArguments(PEXPIRE).key(key).add(milliseconds), BuilderFactory.LONG);
}
public final CommandObject pexpire(byte[] key, long milliseconds) {
return new CommandObject<>(commandArguments(PEXPIRE).key(key).add(milliseconds), BuilderFactory.LONG);
}
public final CommandObject pexpire(String key, long milliseconds, ExpiryOption expiryOption) {
return new CommandObject<>(commandArguments(PEXPIRE).key(key).add(milliseconds).add(expiryOption),
BuilderFactory.LONG);
}
public final CommandObject pexpire(byte[] key, long milliseconds, ExpiryOption expiryOption) {
return new CommandObject<>(commandArguments(PEXPIRE).key(key).add(milliseconds).add(expiryOption),
BuilderFactory.LONG);
}
public final CommandObject expireTime(String key) {
return new CommandObject<>(commandArguments(EXPIRETIME).key(key), BuilderFactory.LONG);
}
public final CommandObject expireTime(byte[] key) {
return new CommandObject<>(commandArguments(EXPIRETIME).key(key), BuilderFactory.LONG);
}
public final CommandObject pexpireTime(String key) {
return new CommandObject<>(commandArguments(PEXPIRETIME).key(key), BuilderFactory.LONG);
}
public final CommandObject pexpireTime(byte[] key) {
return new CommandObject<>(commandArguments(PEXPIRETIME).key(key), BuilderFactory.LONG);
}
public final CommandObject expireAt(String key, long unixTime) {
return new CommandObject<>(commandArguments(EXPIREAT).key(key).add(unixTime), BuilderFactory.LONG);
}
public final CommandObject expireAt(byte[] key, long unixTime) {
return new CommandObject<>(commandArguments(EXPIREAT).key(key).add(unixTime), BuilderFactory.LONG);
}
public final CommandObject expireAt(String key, long unixTime, ExpiryOption expiryOption) {
return new CommandObject<>(commandArguments(EXPIREAT).key(key).add(unixTime).add(expiryOption), BuilderFactory.LONG);
}
public final CommandObject expireAt(byte[] key, long unixTime, ExpiryOption expiryOption) {
return new CommandObject<>(commandArguments(EXPIREAT).key(key).add(unixTime).add(expiryOption), BuilderFactory.LONG);
}
public final CommandObject pexpireAt(String key, long millisecondsTimestamp) {
return new CommandObject<>(commandArguments(PEXPIREAT).key(key).add(millisecondsTimestamp), BuilderFactory.LONG);
}
public final CommandObject pexpireAt(byte[] key, long millisecondsTimestamp) {
return new CommandObject<>(commandArguments(PEXPIREAT).key(key).add(millisecondsTimestamp), BuilderFactory.LONG);
}
public final CommandObject pexpireAt(String key, long millisecondsTimestamp, ExpiryOption expiryOption) {
return new CommandObject<>(commandArguments(PEXPIREAT).key(key).add(millisecondsTimestamp).add(expiryOption),
BuilderFactory.LONG);
}
public final CommandObject pexpireAt(byte[] key, long millisecondsTimestamp, ExpiryOption expiryOption) {
return new CommandObject<>(commandArguments(PEXPIREAT).key(key).add(millisecondsTimestamp).add(expiryOption),
BuilderFactory.LONG);
}
public final CommandObject ttl(String key) {
return new CommandObject<>(commandArguments(TTL).key(key), BuilderFactory.LONG);
}
public final CommandObject ttl(byte[] key) {
return new CommandObject<>(commandArguments(TTL).key(key), BuilderFactory.LONG);
}
public final CommandObject pttl(String key) {
return new CommandObject<>(commandArguments(PTTL).key(key), BuilderFactory.LONG);
}
public final CommandObject pttl(byte[] key) {
return new CommandObject<>(commandArguments(PTTL).key(key), BuilderFactory.LONG);
}
public final CommandObject touch(String key) {
return new CommandObject<>(commandArguments(TOUCH).key(key), BuilderFactory.LONG);
}
public final CommandObject touch(String... keys) {
return new CommandObject<>(commandArguments(TOUCH).keys((Object[]) keys), BuilderFactory.LONG);
}
public final CommandObject touch(byte[] key) {
return new CommandObject<>(commandArguments(TOUCH).key(key), BuilderFactory.LONG);
}
public final CommandObject touch(byte[]... keys) {
return new CommandObject<>(commandArguments(TOUCH).keys((Object[]) keys), BuilderFactory.LONG);
}
public final CommandObject> sort(String key) {
return new CommandObject<>(commandArguments(SORT).key(key), BuilderFactory.STRING_LIST);
}
public final CommandObject> sort(String key, SortingParams sortingParams) {
return new CommandObject<>(commandArguments(SORT).key(key).addParams(sortingParams), BuilderFactory.STRING_LIST);
}
public final CommandObject> sort(byte[] key) {
return new CommandObject<>(commandArguments(SORT).key(key), BuilderFactory.BINARY_LIST);
}
public final CommandObject> sort(byte[] key, SortingParams sortingParams) {
return new CommandObject<>(commandArguments(SORT).key(key).addParams(sortingParams), BuilderFactory.BINARY_LIST);
}
public final CommandObject sort(String key, String dstkey) {
return new CommandObject<>(commandArguments(SORT).key(key)
.add(STORE).key(dstkey), BuilderFactory.LONG);
}
public final CommandObject sort(String key, SortingParams sortingParams, String dstkey) {
return new CommandObject<>(commandArguments(SORT).key(key).addParams(sortingParams)
.add(STORE).key(dstkey), BuilderFactory.LONG);
}
public final CommandObject sort(byte[] key, byte[] dstkey) {
return new CommandObject<>(commandArguments(SORT).key(key)
.add(STORE).key(dstkey), BuilderFactory.LONG);
}
public final CommandObject sort(byte[] key, SortingParams sortingParams, byte[] dstkey) {
return new CommandObject<>(commandArguments(SORT).key(key).addParams(sortingParams)
.add(STORE).key(dstkey), BuilderFactory.LONG);
}
public final CommandObject> sortReadonly(byte[] key, SortingParams sortingParams) {
return new CommandObject<>(commandArguments(SORT_RO).key(key).addParams(sortingParams),
BuilderFactory.BINARY_LIST);
}
public final CommandObject> sortReadonly(String key, SortingParams sortingParams) {
return new CommandObject<>(commandArguments(SORT_RO).key(key).addParams(sortingParams),
BuilderFactory.STRING_LIST);
}
public final CommandObject del(String key) {
return new CommandObject<>(commandArguments(DEL).key(key), BuilderFactory.LONG);
}
public final CommandObject del(String... keys) {
return new CommandObject<>(commandArguments(DEL).keys((Object[]) keys), BuilderFactory.LONG);
}
public final CommandObject del(byte[] key) {
return new CommandObject<>(commandArguments(DEL).key(key), BuilderFactory.LONG);
}
public final CommandObject del(byte[]... keys) {
return new CommandObject<>(commandArguments(DEL).keys((Object[]) keys), BuilderFactory.LONG);
}
public final CommandObject unlink(String key) {
return new CommandObject<>(commandArguments(UNLINK).key(key), BuilderFactory.LONG);
}
public final CommandObject unlink(String... keys) {
return new CommandObject<>(commandArguments(UNLINK).keys((Object[]) keys), BuilderFactory.LONG);
}
public final CommandObject unlink(byte[] key) {
return new CommandObject<>(commandArguments(UNLINK).key(key), BuilderFactory.LONG);
}
public final CommandObject unlink(byte[]... keys) {
return new CommandObject<>(commandArguments(UNLINK).keys((Object[]) keys), BuilderFactory.LONG);
}
public final CommandObject copy(String srcKey, String dstKey, boolean replace) {
CommandArguments args = commandArguments(Command.COPY).key(srcKey).key(dstKey);
if (replace) {
args.add(REPLACE);
}
return new CommandObject<>(args, BuilderFactory.BOOLEAN);
}
public final CommandObject copy(byte[] srcKey, byte[] dstKey, boolean replace) {
CommandArguments args = commandArguments(Command.COPY).key(srcKey).key(dstKey);
if (replace) {
args.add(REPLACE);
}
return new CommandObject<>(args, BuilderFactory.BOOLEAN);
}
public final CommandObject rename(String oldkey, String newkey) {
return new CommandObject<>(commandArguments(RENAME).key(oldkey).key(newkey), BuilderFactory.STRING);
}
public final CommandObject renamenx(String oldkey, String newkey) {
return new CommandObject<>(commandArguments(RENAMENX).key(oldkey).key(newkey), BuilderFactory.LONG);
}
public final CommandObject rename(byte[] oldkey, byte[] newkey) {
return new CommandObject<>(commandArguments(RENAME).key(oldkey).key(newkey), BuilderFactory.STRING);
}
public final CommandObject renamenx(byte[] oldkey, byte[] newkey) {
return new CommandObject<>(commandArguments(RENAMENX).key(oldkey).key(newkey), BuilderFactory.LONG);
}
public CommandObject dbSize() {
return new CommandObject<>(commandArguments(DBSIZE), BuilderFactory.LONG);
}
public CommandObject> keys(String pattern) {
CommandArguments args = commandArguments(Command.KEYS).key(pattern);
return new CommandObject<>(args, BuilderFactory.STRING_SET);
}
public CommandObject> keys(byte[] pattern) {
CommandArguments args = commandArguments(Command.KEYS).key(pattern);
return new CommandObject<>(args, BuilderFactory.BINARY_SET);
}
public CommandObject> scan(String cursor) {
return new CommandObject<>(commandArguments(SCAN).add(cursor), BuilderFactory.SCAN_RESPONSE);
}
public CommandObject> scan(String cursor, ScanParams params) {
return new CommandObject<>(commandArguments(SCAN).add(cursor).addParams(params), BuilderFactory.SCAN_RESPONSE);
}
public CommandObject> scan(String cursor, ScanParams params, String type) {
return new CommandObject<>(commandArguments(SCAN).add(cursor).addParams(params).add(Keyword.TYPE).add(type), BuilderFactory.SCAN_RESPONSE);
}
public CommandObject> scan(byte[] cursor) {
return new CommandObject<>(commandArguments(SCAN).add(cursor), BuilderFactory.SCAN_BINARY_RESPONSE);
}
public CommandObject> scan(byte[] cursor, ScanParams params) {
return new CommandObject<>(commandArguments(SCAN).add(cursor).addParams(params), BuilderFactory.SCAN_BINARY_RESPONSE);
}
public CommandObject> scan(byte[] cursor, ScanParams params, byte[] type) {
return new CommandObject<>(commandArguments(SCAN).add(cursor).addParams(params).add(Keyword.TYPE).add(type), BuilderFactory.SCAN_BINARY_RESPONSE);
}
public final CommandObject randomKey() {
return new CommandObject<>(commandArguments(RANDOMKEY), BuilderFactory.STRING);
}
public final CommandObject randomBinaryKey() {
return new CommandObject<>(commandArguments(RANDOMKEY), BuilderFactory.BINARY);
}
// Key commands
// String commands
public final CommandObject set(String key, String value) {
return new CommandObject<>(commandArguments(Command.SET).key(key).add(value), BuilderFactory.STRING);
}
public final CommandObject set(String key, String value, SetParams params) {
return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).addParams(params), BuilderFactory.STRING);
}
public final CommandObject set(byte[] key, byte[] value) {
return new CommandObject<>(commandArguments(Command.SET).key(key).add(value), BuilderFactory.STRING);
}
public final CommandObject set(byte[] key, byte[] value, SetParams params) {
return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).addParams(params), BuilderFactory.STRING);
}
public final CommandObject get(String key) {
return new CommandObject<>(commandArguments(Command.GET).key(key), BuilderFactory.STRING);
}
public final CommandObject setGet(String key, String value) {
return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).add(Keyword.GET), BuilderFactory.STRING);
}
public final CommandObject setGet(String key, String value, SetParams params) {
return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).addParams(params)
.add(Keyword.GET), BuilderFactory.STRING);
}
public final CommandObject getDel(String key) {
return new CommandObject<>(commandArguments(Command.GETDEL).key(key), BuilderFactory.STRING);
}
public final CommandObject getEx(String key, GetExParams params) {
return new CommandObject<>(commandArguments(Command.GETEX).key(key).addParams(params), BuilderFactory.STRING);
}
public final CommandObject get(byte[] key) {
return new CommandObject<>(commandArguments(Command.GET).key(key), BuilderFactory.BINARY);
}
public final CommandObject setGet(byte[] key, byte[] value) {
return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).add(Keyword.GET), BuilderFactory.BINARY);
}
public final CommandObject setGet(byte[] key, byte[] value, SetParams params) {
return new CommandObject<>(commandArguments(Command.SET).key(key).add(value).addParams(params)
.add(Keyword.GET), BuilderFactory.BINARY);
}
public final CommandObject getDel(byte[] key) {
return new CommandObject<>(commandArguments(Command.GETDEL).key(key), BuilderFactory.BINARY);
}
public final CommandObject getEx(byte[] key, GetExParams params) {
return new CommandObject<>(commandArguments(Command.GETEX).key(key).addParams(params), BuilderFactory.BINARY);
}
public final CommandObject getSet(String key, String value) {
return new CommandObject<>(commandArguments(Command.GETSET).key(key).add(value), BuilderFactory.STRING);
}
public final CommandObject getSet(byte[] key, byte[] value) {
return new CommandObject<>(commandArguments(Command.GETSET).key(key).add(value), BuilderFactory.BINARY);
}
public final CommandObject setnx(String key, String value) {
return new CommandObject<>(commandArguments(SETNX).key(key).add(value), BuilderFactory.LONG);
}
public final CommandObject setex(String key, long seconds, String value) {
return new CommandObject<>(commandArguments(SETEX).key(key).add(seconds).add(value), BuilderFactory.STRING);
}
public final CommandObject psetex(String key, long milliseconds, String value) {
return new CommandObject<>(commandArguments(PSETEX).key(key).add(milliseconds).add(value), BuilderFactory.STRING);
}
public final CommandObject setnx(byte[] key, byte[] value) {
return new CommandObject<>(commandArguments(SETNX).key(key).add(value), BuilderFactory.LONG);
}
public final CommandObject setex(byte[] key, long seconds, byte[] value) {
return new CommandObject<>(commandArguments(SETEX).key(key).add(seconds).add(value), BuilderFactory.STRING);
}
public final CommandObject psetex(byte[] key, long milliseconds, byte[] value) {
return new CommandObject<>(commandArguments(PSETEX).key(key).add(milliseconds).add(value), BuilderFactory.STRING);
}
public final CommandObject setbit(String key, long offset, boolean value) {
return new CommandObject<>(commandArguments(SETBIT).key(key).add(offset).add(value), BuilderFactory.BOOLEAN);
}
public final CommandObject setbit(byte[] key, long offset, boolean value) {
return new CommandObject<>(commandArguments(SETBIT).key(key).add(offset).add(value), BuilderFactory.BOOLEAN);
}
public final CommandObject getbit(String key, long offset) {
return new CommandObject<>(commandArguments(GETBIT).key(key).add(offset), BuilderFactory.BOOLEAN);
}
public final CommandObject getbit(byte[] key, long offset) {
return new CommandObject<>(commandArguments(GETBIT).key(key).add(offset), BuilderFactory.BOOLEAN);
}
public final CommandObject setrange(String key, long offset, String value) {
return new CommandObject<>(commandArguments(SETRANGE).key(key).add(offset).add(value), BuilderFactory.LONG);
}
public final CommandObject setrange(byte[] key, long offset, byte[] value) {
return new CommandObject<>(commandArguments(SETRANGE).key(key).add(offset).add(value), BuilderFactory.LONG);
}
public final CommandObject getrange(String key, long startOffset, long endOffset) {
return new CommandObject<>(commandArguments(GETRANGE).key(key).add(startOffset).add(endOffset), BuilderFactory.STRING);
}
public final CommandObject getrange(byte[] key, long startOffset, long endOffset) {
return new CommandObject<>(commandArguments(GETRANGE).key(key).add(startOffset).add(endOffset), BuilderFactory.BINARY);
}
public final CommandObject> mget(String... keys) {
return new CommandObject<>(commandArguments(MGET).keys((Object[]) keys), BuilderFactory.STRING_LIST);
}
public final CommandObject> mget(byte[]... keys) {
return new CommandObject<>(commandArguments(MGET).keys((Object[]) keys), BuilderFactory.BINARY_LIST);
}
public final CommandObject mset(String... keysvalues) {
return new CommandObject<>(addFlatKeyValueArgs(commandArguments(MSET), keysvalues), BuilderFactory.STRING);
}
public final CommandObject msetnx(String... keysvalues) {
return new CommandObject<>(addFlatKeyValueArgs(commandArguments(MSETNX), keysvalues), BuilderFactory.LONG);
}
public final CommandObject mset(byte[]... keysvalues) {
return new CommandObject<>(addFlatKeyValueArgs(commandArguments(MSET), keysvalues), BuilderFactory.STRING);
}
public final CommandObject msetnx(byte[]... keysvalues) {
return new CommandObject<>(addFlatKeyValueArgs(commandArguments(MSETNX), keysvalues), BuilderFactory.LONG);
}
public final CommandObject incr(String key) {
return new CommandObject<>(commandArguments(Command.INCR).key(key), BuilderFactory.LONG);
}
public final CommandObject incrBy(String key, long increment) {
return new CommandObject<>(commandArguments(INCRBY).key(key).add(increment), BuilderFactory.LONG);
}
public final CommandObject incrByFloat(String key, double increment) {
return new CommandObject<>(commandArguments(INCRBYFLOAT).key(key).add(increment), BuilderFactory.DOUBLE);
}
public final CommandObject incr(byte[] key) {
return new CommandObject<>(commandArguments(Command.INCR).key(key), BuilderFactory.LONG);
}
public final CommandObject incrBy(byte[] key, long increment) {
return new CommandObject<>(commandArguments(INCRBY).key(key).add(increment), BuilderFactory.LONG);
}
public final CommandObject incrByFloat(byte[] key, double increment) {
return new CommandObject<>(commandArguments(INCRBYFLOAT).key(key).add(increment), BuilderFactory.DOUBLE);
}
public final CommandObject decr(String key) {
return new CommandObject<>(commandArguments(DECR).key(key), BuilderFactory.LONG);
}
public final CommandObject decrBy(String key, long decrement) {
return new CommandObject<>(commandArguments(DECRBY).key(key).add(decrement), BuilderFactory.LONG);
}
public final CommandObject decr(byte[] key) {
return new CommandObject<>(commandArguments(DECR).key(key), BuilderFactory.LONG);
}
public final CommandObject decrBy(byte[] key, long decrement) {
return new CommandObject<>(commandArguments(DECRBY).key(key).add(decrement), BuilderFactory.LONG);
}
public final CommandObject append(String key, String value) {
return new CommandObject<>(commandArguments(APPEND).key(key).add(value), BuilderFactory.LONG);
}
public final CommandObject append(byte[] key, byte[] value) {
return new CommandObject<>(commandArguments(APPEND).key(key).add(value), BuilderFactory.LONG);
}
public final CommandObject substr(String key, int start, int end) {
return new CommandObject<>(commandArguments(SUBSTR).key(key).add(start).add(end), BuilderFactory.STRING);
}
public final CommandObject substr(byte[] key, int start, int end) {
return new CommandObject<>(commandArguments(SUBSTR).key(key).add(start).add(end), BuilderFactory.BINARY);
}
public final CommandObject strlen(String key) {
return new CommandObject<>(commandArguments(STRLEN).key(key), BuilderFactory.LONG);
}
public final CommandObject strlen(byte[] key) {
return new CommandObject<>(commandArguments(STRLEN).key(key), BuilderFactory.LONG);
}
public final CommandObject bitcount(String key) {
return new CommandObject<>(commandArguments(BITCOUNT).key(key), BuilderFactory.LONG);
}
public final CommandObject bitcount(String key, long start, long end) {
return new CommandObject<>(commandArguments(BITCOUNT).key(key).add(start).add(end), BuilderFactory.LONG);
}
public final CommandObject bitcount(String key, long start, long end, BitCountOption option) {
return new CommandObject<>(commandArguments(BITCOUNT).key(key).add(start).add(end).add(option), BuilderFactory.LONG);
}
public final CommandObject bitcount(byte[] key) {
return new CommandObject<>(commandArguments(BITCOUNT).key(key), BuilderFactory.LONG);
}
public final CommandObject bitcount(byte[] key, long start, long end) {
return new CommandObject<>(commandArguments(BITCOUNT).key(key).add(start).add(end), BuilderFactory.LONG);
}
public final CommandObject bitcount(byte[] key, long start, long end, BitCountOption option) {
return new CommandObject<>(commandArguments(BITCOUNT).key(key).add(start).add(end).add(option), BuilderFactory.LONG);
}
public final CommandObject bitpos(String key, boolean value) {
return new CommandObject<>(commandArguments(BITPOS).key(key).add(value ? 1 : 0), BuilderFactory.LONG);
}
public final CommandObject bitpos(String key, boolean value, BitPosParams params) {
return new CommandObject<>(commandArguments(BITPOS).key(key).add(value ? 1 : 0).addParams(params), BuilderFactory.LONG);
}
public final CommandObject bitpos(byte[] key, boolean value) {
return new CommandObject<>(commandArguments(BITPOS).key(key).add(value ? 1 : 0), BuilderFactory.LONG);
}
public final CommandObject bitpos(byte[] key, boolean value, BitPosParams params) {
return new CommandObject<>(commandArguments(BITPOS).key(key).add(value ? 1 : 0).addParams(params), BuilderFactory.LONG);
}
public final CommandObject> bitfield(String key, String... arguments) {
return new CommandObject<>(commandArguments(BITFIELD).key(key).addObjects((Object[]) arguments), BuilderFactory.LONG_LIST);
}
public final CommandObject> bitfieldReadonly(String key, String... arguments) {
return new CommandObject<>(commandArguments(BITFIELD_RO).key(key).addObjects((Object[]) arguments), BuilderFactory.LONG_LIST);
}
public final CommandObject> bitfield(byte[] key, byte[]... arguments) {
return new CommandObject<>(commandArguments(BITFIELD).key(key).addObjects((Object[]) arguments), BuilderFactory.LONG_LIST);
}
public final CommandObject> bitfieldReadonly(byte[] key, byte[]... arguments) {
return new CommandObject<>(commandArguments(BITFIELD_RO).key(key).addObjects((Object[]) arguments), BuilderFactory.LONG_LIST);
}
public final CommandObject bitop(BitOP op, String destKey, String... srcKeys) {
return new CommandObject<>(commandArguments(BITOP).add(op).key(destKey).keys((Object[]) srcKeys), BuilderFactory.LONG);
}
public final CommandObject bitop(BitOP op, byte[] destKey, byte[]... srcKeys) {
return new CommandObject<>(commandArguments(BITOP).add(op).key(destKey).keys((Object[]) srcKeys), BuilderFactory.LONG);
}
public final CommandObject lcs(String keyA, String keyB, LCSParams params) {
return new CommandObject<>(commandArguments(Command.LCS).key(keyA).key(keyB)
.addParams(params), BuilderFactory.STR_ALGO_LCS_RESULT_BUILDER);
}
public final CommandObject lcs(byte[] keyA, byte[] keyB, LCSParams params) {
return new CommandObject<>(commandArguments(Command.LCS).key(keyA).key(keyB)
.addParams(params), BuilderFactory.STR_ALGO_LCS_RESULT_BUILDER);
}
// String commands
// List commands
public final CommandObject rpush(String key, String... strings) {
return new CommandObject<>(commandArguments(RPUSH).key(key).addObjects((Object[]) strings), BuilderFactory.LONG);
}
public final CommandObject rpush(byte[] key, byte[]... strings) {
return new CommandObject<>(commandArguments(RPUSH).key(key).addObjects((Object[]) strings), BuilderFactory.LONG);
}
public final CommandObject lpush(String key, String... strings) {
return new CommandObject<>(commandArguments(LPUSH).key(key).addObjects((Object[]) strings), BuilderFactory.LONG);
}
public final CommandObject lpush(byte[] key, byte[]... strings) {
return new CommandObject<>(commandArguments(LPUSH).key(key).addObjects((Object[]) strings), BuilderFactory.LONG);
}
public final CommandObject llen(String key) {
return new CommandObject<>(commandArguments(LLEN).key(key), BuilderFactory.LONG);
}
public final CommandObject llen(byte[] key) {
return new CommandObject<>(commandArguments(LLEN).key(key), BuilderFactory.LONG);
}
public final CommandObject> lrange(String key, long start, long stop) {
return new CommandObject<>(commandArguments(LRANGE).key(key).add(start).add(stop), BuilderFactory.STRING_LIST);
}
public final CommandObject> lrange(byte[] key, long start, long stop) {
return new CommandObject<>(commandArguments(LRANGE).key(key).add(start).add(stop), BuilderFactory.BINARY_LIST);
}
public final CommandObject ltrim(String key, long start, long stop) {
return new CommandObject<>(commandArguments(LTRIM).key(key).add(start).add(stop), BuilderFactory.STRING);
}
public final CommandObject ltrim(byte[] key, long start, long stop) {
return new CommandObject<>(commandArguments(LTRIM).key(key).add(start).add(stop), BuilderFactory.STRING);
}
public final CommandObject lindex(String key, long index) {
return new CommandObject<>(commandArguments(LINDEX).key(key).add(index), BuilderFactory.STRING);
}
public final CommandObject lindex(byte[] key, long index) {
return new CommandObject<>(commandArguments(LINDEX).key(key).add(index), BuilderFactory.BINARY);
}
public final CommandObject lset(String key, long index, String value) {
return new CommandObject<>(commandArguments(LSET).key(key).add(index).add(value), BuilderFactory.STRING);
}
public final CommandObject lset(byte[] key, long index, byte[] value) {
return new CommandObject<>(commandArguments(LSET).key(key).add(index).add(value), BuilderFactory.STRING);
}
public final CommandObject lrem(String key, long count, String value) {
return new CommandObject<>(commandArguments(LREM).key(key).add(count).add(value), BuilderFactory.LONG);
}
public final CommandObject lrem(byte[] key, long count, byte[] value) {
return new CommandObject<>(commandArguments(LREM).key(key).add(count).add(value), BuilderFactory.LONG);
}
public final CommandObject lpop(String key) {
return new CommandObject<>(commandArguments(LPOP).key(key), BuilderFactory.STRING);
}
public final CommandObject> lpop(String key, int count) {
return new CommandObject<>(commandArguments(LPOP).key(key).add(count), BuilderFactory.STRING_LIST);
}
public final CommandObject lpop(byte[] key) {
return new CommandObject<>(commandArguments(LPOP).key(key), BuilderFactory.BINARY);
}
public final CommandObject> lpop(byte[] key, int count) {
return new CommandObject<>(commandArguments(LPOP).key(key).add(count), BuilderFactory.BINARY_LIST);
}
public final CommandObject rpop(String key) {
return new CommandObject<>(commandArguments(RPOP).key(key), BuilderFactory.STRING);
}
public final CommandObject> rpop(String key, int count) {
return new CommandObject<>(commandArguments(RPOP).key(key).add(count), BuilderFactory.STRING_LIST);
}
public final CommandObject rpop(byte[] key) {
return new CommandObject<>(commandArguments(RPOP).key(key), BuilderFactory.BINARY);
}
public final CommandObject> rpop(byte[] key, int count) {
return new CommandObject<>(commandArguments(RPOP).key(key).add(count), BuilderFactory.BINARY_LIST);
}
public final CommandObject lpos(String key, String element) {
return new CommandObject<>(commandArguments(LPOS).key(key).add(element), BuilderFactory.LONG);
}
public final CommandObject lpos(String key, String element, LPosParams params) {
return new CommandObject<>(commandArguments(LPOS).key(key).add(element).addParams(params), BuilderFactory.LONG);
}
public final CommandObject> lpos(String key, String element, LPosParams params, long count) {
return new CommandObject<>(commandArguments(LPOS).key(key).add(element)
.addParams(params).add(COUNT).add(count), BuilderFactory.LONG_LIST);
}
public final CommandObject lpos(byte[] key, byte[] element) {
return new CommandObject<>(commandArguments(LPOS).key(key).add(element), BuilderFactory.LONG);
}
public final CommandObject lpos(byte[] key, byte[] element, LPosParams params) {
return new CommandObject<>(commandArguments(LPOS).key(key).add(element).addParams(params), BuilderFactory.LONG);
}
public final CommandObject> lpos(byte[] key, byte[] element, LPosParams params, long count) {
return new CommandObject<>(commandArguments(LPOS).key(key).add(element)
.addParams(params).add(COUNT).add(count), BuilderFactory.LONG_LIST);
}
public final CommandObject linsert(String key, ListPosition where, String pivot, String value) {
return new CommandObject<>(commandArguments(LINSERT).key(key).add(where)
.add(pivot).add(value), BuilderFactory.LONG);
}
public final CommandObject linsert(byte[] key, ListPosition where, byte[] pivot, byte[] value) {
return new CommandObject<>(commandArguments(LINSERT).key(key).add(where)
.add(pivot).add(value), BuilderFactory.LONG);
}
public final CommandObject lpushx(String key, String... strings) {
return new CommandObject<>(commandArguments(LPUSHX).key(key).addObjects((Object[]) strings), BuilderFactory.LONG);
}
public final CommandObject rpushx(String key, String... strings) {
return new CommandObject<>(commandArguments(RPUSHX).key(key).addObjects((Object[]) strings), BuilderFactory.LONG);
}
public final CommandObject lpushx(byte[] key, byte[]... args) {
return new CommandObject<>(commandArguments(LPUSHX).key(key).addObjects((Object[]) args), BuilderFactory.LONG);
}
public final CommandObject rpushx(byte[] key, byte[]... args) {
return new CommandObject<>(commandArguments(RPUSHX).key(key).addObjects((Object[]) args), BuilderFactory.LONG);
}
public final CommandObject> blpop(int timeout, String key) {
return new CommandObject<>(commandArguments(BLPOP).blocking().key(key).add(timeout), BuilderFactory.STRING_LIST);
}
public final CommandObject> blpop(int timeout, String... keys) {
return new CommandObject<>(commandArguments(BLPOP).blocking().keys((Object[]) keys).add(timeout), BuilderFactory.STRING_LIST);
}
public final CommandObject> blpop(double timeout, String key) {
return new CommandObject<>(commandArguments(BLPOP).blocking().key(key).add(timeout), BuilderFactory.KEYED_ELEMENT);
}
public final CommandObject> blpop(double timeout, String... keys) {
return new CommandObject<>(commandArguments(BLPOP).blocking().keys((Object[]) keys).add(timeout), BuilderFactory.KEYED_ELEMENT);
}
public final CommandObject> blpop(int timeout, byte[]... keys) {
return new CommandObject<>(commandArguments(BLPOP).blocking().keys((Object[]) keys).add(timeout), BuilderFactory.BINARY_LIST);
}
public final CommandObject> blpop(double timeout, byte[]... keys) {
return new CommandObject<>(commandArguments(BLPOP).blocking().keys((Object[]) keys).add(timeout), BuilderFactory.BINARY_KEYED_ELEMENT);
}
public final CommandObject> brpop(int timeout, String key) {
return new CommandObject<>(commandArguments(BRPOP).blocking().key(key).add(timeout), BuilderFactory.STRING_LIST);
}
public final CommandObject> brpop(int timeout, String... keys) {
return new CommandObject<>(commandArguments(BRPOP).blocking().keys((Object[]) keys).add(timeout), BuilderFactory.STRING_LIST);
}
public final CommandObject> brpop(double timeout, String key) {
return new CommandObject<>(commandArguments(BRPOP).blocking().key(key).add(timeout), BuilderFactory.KEYED_ELEMENT);
}
public final CommandObject> brpop(double timeout, String... keys) {
return new CommandObject<>(commandArguments(BRPOP).blocking().keys((Object[]) keys).add(timeout), BuilderFactory.KEYED_ELEMENT);
}
public final CommandObject> brpop(int timeout, byte[]... keys) {
return new CommandObject<>(commandArguments(BRPOP).blocking().keys((Object[]) keys).add(timeout), BuilderFactory.BINARY_LIST);
}
public final CommandObject> brpop(double timeout, byte[]... keys) {
return new CommandObject<>(commandArguments(BRPOP).blocking().keys((Object[]) keys).add(timeout), BuilderFactory.BINARY_KEYED_ELEMENT);
}
public final CommandObject rpoplpush(String srckey, String dstkey) {
return new CommandObject<>(commandArguments(RPOPLPUSH).key(srckey).key(dstkey), BuilderFactory.STRING);
}
public final CommandObject brpoplpush(String source, String destination, int timeout) {
return new CommandObject<>(commandArguments(BRPOPLPUSH).blocking().key(source)
.key(destination).add(timeout), BuilderFactory.STRING);
}
public final CommandObject rpoplpush(byte[] srckey, byte[] dstkey) {
return new CommandObject<>(commandArguments(RPOPLPUSH).key(srckey).key(dstkey), BuilderFactory.BINARY);
}
public final CommandObject brpoplpush(byte[] source, byte[] destination, int timeout) {
return new CommandObject<>(commandArguments(BRPOPLPUSH).blocking().key(source)
.key(destination).add(timeout), BuilderFactory.BINARY);
}
public final CommandObject lmove(String srcKey, String dstKey, ListDirection from, ListDirection to) {
return new CommandObject<>(commandArguments(LMOVE).key(srcKey).key(dstKey)
.add(from).add(to), BuilderFactory.STRING);
}
public final CommandObject blmove(String srcKey, String dstKey, ListDirection from, ListDirection to, double timeout) {
return new CommandObject<>(commandArguments(BLMOVE).blocking().key(srcKey)
.key(dstKey).add(from).add(to).add(timeout), BuilderFactory.STRING);
}
public final CommandObject lmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to) {
return new CommandObject<>(commandArguments(LMOVE).key(srcKey).key(dstKey)
.add(from).add(to), BuilderFactory.BINARY);
}
public final CommandObject blmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to, double timeout) {
return new CommandObject<>(commandArguments(BLMOVE).blocking().key(srcKey)
.key(dstKey).add(from).add(to).add(timeout), BuilderFactory.BINARY);
}
public final CommandObject>> lmpop(ListDirection direction, String... keys) {
return new CommandObject<>(commandArguments(LMPOP).add(keys.length).keys((Object[]) keys)
.add(direction), BuilderFactory.KEYED_STRING_LIST);
}
public final CommandObject>> lmpop(ListDirection direction, int count, String... keys) {
return new CommandObject<>(commandArguments(LMPOP).add(keys.length).keys((Object[]) keys)
.add(direction).add(COUNT).add(count), BuilderFactory.KEYED_STRING_LIST);
}
public final CommandObject>> blmpop(double timeout, ListDirection direction, String... keys) {
return new CommandObject<>(commandArguments(BLMPOP).blocking().add(timeout)
.add(keys.length).keys((Object[]) keys).add(direction), BuilderFactory.KEYED_STRING_LIST);
}
public final CommandObject>> blmpop(double timeout, ListDirection direction, int count, String... keys) {
return new CommandObject<>(commandArguments(BLMPOP).blocking().add(timeout)
.add(keys.length).keys((Object[]) keys).add(direction).add(COUNT).add(count),
BuilderFactory.KEYED_STRING_LIST);
}
public final CommandObject>> lmpop(ListDirection direction, byte[]... keys) {
return new CommandObject<>(commandArguments(LMPOP).add(keys.length).keys((Object[]) keys)
.add(direction), BuilderFactory.KEYED_BINARY_LIST);
}
public final CommandObject>> lmpop(ListDirection direction, int count, byte[]... keys) {
return new CommandObject<>(commandArguments(LMPOP).add(keys.length).keys((Object[]) keys)
.add(direction).add(COUNT).add(count), BuilderFactory.KEYED_BINARY_LIST);
}
public final CommandObject>> blmpop(double timeout, ListDirection direction, byte[]... keys) {
return new CommandObject<>(commandArguments(BLMPOP).blocking().add(timeout)
.add(keys.length).keys((Object[]) keys).add(direction), BuilderFactory.KEYED_BINARY_LIST);
}
public final CommandObject>> blmpop(double timeout, ListDirection direction, int count, byte[]... keys) {
return new CommandObject<>(commandArguments(BLMPOP).blocking().add(timeout)
.add(keys.length).keys((Object[]) keys).add(direction).add(COUNT).add(count),
BuilderFactory.KEYED_BINARY_LIST);
}
// List commands
// Hash commands
public final CommandObject hset(String key, String field, String value) {
return new CommandObject<>(commandArguments(HSET).key(key).add(field).add(value), BuilderFactory.LONG);
}
public final CommandObject hset(String key, Map hash) {
return new CommandObject<>(addFlatMapArgs(commandArguments(HSET).key(key), hash), BuilderFactory.LONG);
}
public final CommandObject hget(String key, String field) {
return new CommandObject<>(commandArguments(HGET).key(key).add(field), BuilderFactory.STRING);
}
public final CommandObject hsetnx(String key, String field, String value) {
return new CommandObject<>(commandArguments(HSETNX).key(key).add(field).add(value), BuilderFactory.LONG);
}
public final CommandObject hmset(String key, Map hash) {
return new CommandObject<>(addFlatMapArgs(commandArguments(HMSET).key(key), hash), BuilderFactory.STRING);
}
public final CommandObject> hmget(String key, String... fields) {
return new CommandObject<>(commandArguments(HMGET).key(key).addObjects((Object[]) fields), BuilderFactory.STRING_LIST);
}
public final CommandObject hset(byte[] key, byte[] field, byte[] value) {
return new CommandObject<>(commandArguments(HSET).key(key).add(field).add(value), BuilderFactory.LONG);
}
public final CommandObject hset(byte[] key, Map hash) {
return new CommandObject<>(addFlatMapArgs(commandArguments(HSET).key(key), hash), BuilderFactory.LONG);
}
public final CommandObject hget(byte[] key, byte[] field) {
return new CommandObject<>(commandArguments(HGET).key(key).add(field), BuilderFactory.BINARY);
}
public final CommandObject hsetnx(byte[] key, byte[] field, byte[] value) {
return new CommandObject<>(commandArguments(HSETNX).key(key).add(field).add(value), BuilderFactory.LONG);
}
public final CommandObject hmset(byte[] key, Map hash) {
return new CommandObject<>(addFlatMapArgs(commandArguments(HMSET).key(key), hash), BuilderFactory.STRING);
}
public final CommandObject> hmget(byte[] key, byte[]... fields) {
return new CommandObject<>(commandArguments(HMGET).key(key).addObjects((Object[]) fields), BuilderFactory.BINARY_LIST);
}
public final CommandObject hincrBy(String key, String field, long value) {
return new CommandObject<>(commandArguments(HINCRBY).key(key).add(field).add(value), BuilderFactory.LONG);
}
public final CommandObject hincrByFloat(String key, String field, double value) {
return new CommandObject<>(commandArguments(HINCRBYFLOAT).key(key).add(field).add(value), BuilderFactory.DOUBLE);
}
public final CommandObject hexists(String key, String field) {
return new CommandObject<>(commandArguments(HEXISTS).key(key).add(field), BuilderFactory.BOOLEAN);
}
public final CommandObject hdel(String key, String... field) {
return new CommandObject<>(commandArguments(HDEL).key(key).addObjects((Object[]) field), BuilderFactory.LONG);
}
public final CommandObject hlen(String key) {
return new CommandObject<>(commandArguments(HLEN).key(key), BuilderFactory.LONG);
}
public final CommandObject hincrBy(byte[] key, byte[] field, long value) {
return new CommandObject<>(commandArguments(HINCRBY).key(key).add(field).add(value), BuilderFactory.LONG);
}
public final CommandObject hincrByFloat(byte[] key, byte[] field, double value) {
return new CommandObject<>(commandArguments(HINCRBYFLOAT).key(key).add(field).add(value), BuilderFactory.DOUBLE);
}
public final CommandObject hexists(byte[] key, byte[] field) {
return new CommandObject<>(commandArguments(HEXISTS).key(key).add(field), BuilderFactory.BOOLEAN);
}
public final CommandObject hdel(byte[] key, byte[]... field) {
return new CommandObject<>(commandArguments(HDEL).key(key).addObjects((Object[]) field), BuilderFactory.LONG);
}
public final CommandObject hlen(byte[] key) {
return new CommandObject<>(commandArguments(HLEN).key(key), BuilderFactory.LONG);
}
public final CommandObject> hkeys(String key) {
return new CommandObject<>(commandArguments(HKEYS).key(key), BuilderFactory.STRING_SET);
}
public final CommandObject> hvals(String key) {
return new CommandObject<>(commandArguments(HVALS).key(key), BuilderFactory.STRING_LIST);
}
public final CommandObject> hkeys(byte[] key) {
return new CommandObject<>(commandArguments(HKEYS).key(key), BuilderFactory.BINARY_SET);
}
public final CommandObject> hvals(byte[] key) {
return new CommandObject<>(commandArguments(HVALS).key(key), BuilderFactory.BINARY_LIST);
}
public final CommandObject