Package io.lettuce.core.protocol
Class CommandArgs<K,V>
- java.lang.Object
-
- io.lettuce.core.protocol.CommandArgs<K,V>
-
- Type Parameters:
K
- Key type.V
- Value type.
public class CommandArgs<K,V> extends Object
Redis command arguments.CommandArgs
is a container for multiple singular arguments. Key and Value arguments are encoded using theRedisCodec
to their byte representation.CommandArgs
provides a fluent style of adding multiple arguments. ACommandArgs
instance can be reused across multiple commands and invocations.Example
new CommandArgs<>(codec).addKey(key).addValue(value).add(CommandKeyword.FORCE);
- Author:
- Will Glozer, Mark Paluch, shikharid
-
-
Field Summary
Fields Modifier and Type Field Description protected RedisCodec<K,V>
codec
-
Constructor Summary
Constructors Constructor Description CommandArgs(RedisCodec<K,V> codec)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CommandArgs<K,V>
add(byte[] value)
Add a byte-array argument.CommandArgs<K,V>
add(char[] cs)
Add a string as char-array.CommandArgs<K,V>
add(double n)
Add a double argument.CommandArgs<K,V>
add(long n)
Add an 64-bit integer (long) argument.CommandArgs<K,V>
add(CommandKeyword keyword)
Add aCommandKeyword
argument.CommandArgs<K,V>
add(CommandType type)
Add aCommandType
argument.CommandArgs<K,V>
add(ProtocolKeyword keyword)
Add aProtocolKeyword
argument.CommandArgs<K,V>
add(String s)
Add a string argument.CommandArgs<K,V>
add(Map<K,V> map)
Add a map (hash) argument.CommandArgs<K,V>
addAll(CommandArgs<?,?> args)
Add all arguments fromCommandArgs
CommandArgs<K,V>
addKey(K key)
Adds a key argument.CommandArgs<K,V>
addKeys(Iterable<K> keys)
Add multiple key arguments.CommandArgs<K,V>
addKeys(K... keys)
Add multiple key arguments.CommandArgs<K,V>
addValue(V value)
Add a value argument.CommandArgs<K,V>
addValues(Iterable<V> values)
Add multiple value arguments.CommandArgs<K,V>
addValues(V... values)
Add multiple value arguments.int
count()
void
encode(ByteBuf buf)
Encode theCommandArgs
and write the arguments to theByteBuf
.ByteBuffer
getFirstEncodedKey()
Returns the first key argument in its byte-encoded representation.Long
getFirstInteger()
Deprecated.String
getFirstString()
Deprecated.String
toCommandString()
Returns a command string representation ofCommandArgs
with annotated key and value parameters.String
toString()
-
-
-
Field Detail
-
codec
protected final RedisCodec<K,V> codec
-
-
Constructor Detail
-
CommandArgs
public CommandArgs(RedisCodec<K,V> codec)
- Parameters:
codec
- Codec used to encode/decode keys and values, must not benull
.
-
-
Method Detail
-
count
public int count()
- Returns:
- the number of arguments.
-
addKey
public CommandArgs<K,V> addKey(K key)
Adds a key argument.- Parameters:
key
- the key- Returns:
- the command args.
-
addKeys
public CommandArgs<K,V> addKeys(Iterable<K> keys)
Add multiple key arguments.- Parameters:
keys
- must not benull
.- Returns:
- the command args.
-
addKeys
@SafeVarargs public final CommandArgs<K,V> addKeys(K... keys)
Add multiple key arguments.- Parameters:
keys
- must not benull
.- Returns:
- the command args.
-
addValue
public CommandArgs<K,V> addValue(V value)
Add a value argument.- Parameters:
value
- the value- Returns:
- the command args.
-
addValues
public CommandArgs<K,V> addValues(Iterable<V> values)
Add multiple value arguments.- Parameters:
values
- must not benull
.- Returns:
- the command args.
-
addValues
@SafeVarargs public final CommandArgs<K,V> addValues(V... values)
Add multiple value arguments.- Parameters:
values
- must not benull
.- Returns:
- the command args.
-
add
public CommandArgs<K,V> add(Map<K,V> map)
Add a map (hash) argument.- Parameters:
map
- the map, must not benull
.- Returns:
- the command args.
-
add
public CommandArgs<K,V> add(String s)
Add a string argument. The argument is represented as bulk string.- Parameters:
s
- the string.- Returns:
- the command args.
-
add
public CommandArgs<K,V> add(char[] cs)
Add a string as char-array. The argument is represented as bulk string.- Parameters:
cs
- the string.- Returns:
- the command args.
-
add
public CommandArgs<K,V> add(long n)
Add an 64-bit integer (long) argument.- Parameters:
n
- the argument.- Returns:
- the command args.
-
add
public CommandArgs<K,V> add(double n)
Add a double argument.- Parameters:
n
- the double argument.- Returns:
- the command args.
-
add
public CommandArgs<K,V> add(byte[] value)
Add a byte-array argument. The argument is represented as bulk string.- Parameters:
value
- the byte-array.- Returns:
- the command args.
-
add
public CommandArgs<K,V> add(CommandKeyword keyword)
Add aCommandKeyword
argument. The argument is represented as bulk string.- Parameters:
keyword
- must not benull
.- Returns:
- the command args.
-
add
public CommandArgs<K,V> add(CommandType type)
Add aCommandType
argument. The argument is represented as bulk string.- Parameters:
type
- must not benull
.- Returns:
- the command args.
-
add
public CommandArgs<K,V> add(ProtocolKeyword keyword)
Add aProtocolKeyword
argument. The argument is represented as bulk string.- Parameters:
keyword
- the keyword, must not benull
- Returns:
- the command args.
-
addAll
public CommandArgs<K,V> addAll(CommandArgs<?,?> args)
Add all arguments fromCommandArgs
- Parameters:
args
- the args, must not benull
- Returns:
- the command args.
- Since:
- 6.2
-
toCommandString
public String toCommandString()
Returns a command string representation ofCommandArgs
with annotated key and value parameters.args.addKey("mykey").add(2.0)
will returnkey<mykey> 2.0
.- Returns:
- the command string representation.
-
getFirstInteger
@Deprecated public Long getFirstInteger()
Deprecated.Returns the first integer argument.- Returns:
- the first integer argument or
null
.
-
getFirstString
@Deprecated public String getFirstString()
Deprecated.Returns the first string argument.- Returns:
- the first string argument or
null
.
-
getFirstEncodedKey
public ByteBuffer getFirstEncodedKey()
Returns the first key argument in its byte-encoded representation.- Returns:
- the first key argument in its byte-encoded representation or
null
.
-
encode
public void encode(ByteBuf buf)
Encode theCommandArgs
and write the arguments to theByteBuf
.- Parameters:
buf
- the target buffer.
-
-