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 the RedisCodec to their byte representation. CommandArgs provides a fluent style of adding
multiple arguments. A CommandArgs 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
-
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
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 aCommandKeywordargument.CommandArgs<K,V>add(CommandType type)Add aCommandTypeargument.CommandArgs<K,V>add(ProtocolKeyword keyword)Add aProtocolKeywordargument.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>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.intcount()voidencode(ByteBuf buf)Encode theCommandArgsand write the arguments to theByteBuf.ByteBuffergetFirstEncodedKey()Returns the first key argument in its byte-encoded representation.LonggetFirstInteger()Deprecated.StringgetFirstString()Deprecated.StringtoCommandString()Returns a command string representation ofCommandArgswith annotated key and value parameters.StringtoString()
-
Field Details
-
codec
-
-
Constructor Details
-
CommandArgs
- Parameters:
codec- Codec used to encode/decode keys and values, must not benull.
-
-
Method Details
-
count
public int count()- Returns:
- the number of arguments.
-
addKey
Adds a key argument.- Parameters:
key- the key- Returns:
- the command args.
-
addKeys
Add multiple key arguments.- Parameters:
keys- must not benull.- Returns:
- the command args.
-
addKeys
Add multiple key arguments.- Parameters:
keys- must not benull.- Returns:
- the command args.
-
addValue
Add a value argument.- Parameters:
value- the value- Returns:
- the command args.
-
addValues
Add multiple value arguments.- Parameters:
values- must not benull.- Returns:
- the command args.
-
addValues
Add multiple value arguments.- Parameters:
values- must not benull.- Returns:
- the command args.
-
add
Add a map (hash) argument.- Parameters:
map- the map, must not benull.- Returns:
- the command args.
-
add
Add a string argument. The argument is represented as bulk string.- Parameters:
s- the string.- Returns:
- the command args.
-
add
Add a string as char-array. The argument is represented as bulk string.- Parameters:
cs- the string.- Returns:
- the command args.
-
add
Add an 64-bit integer (long) argument.- Parameters:
n- the argument.- Returns:
- the command args.
-
add
Add a double argument.- Parameters:
n- the double argument.- Returns:
- the command args.
-
add
Add a byte-array argument. The argument is represented as bulk string.- Parameters:
value- the byte-array.- Returns:
- the command args.
-
add
Add aCommandKeywordargument. The argument is represented as bulk string.- Parameters:
keyword- must not benull.- Returns:
- the command args.
-
add
Add aCommandTypeargument. The argument is represented as bulk string.- Parameters:
type- must not benull.- Returns:
- the command args.
-
add
Add aProtocolKeywordargument. The argument is represented as bulk string.- Parameters:
keyword- the keyword, must not benull- Returns:
- the command args.
-
toString
-
toCommandString
Returns a command string representation ofCommandArgswith annotated key and value parameters.args.addKey("mykey").add(2.0)will returnkey<mykey> 2.0.- Returns:
- the command string representation.
-
getFirstInteger
Deprecated.Returns the first integer argument.- Returns:
- the first integer argument or
null.
-
getFirstString
Deprecated.Returns the first string argument.- Returns:
- the first string argument or
null.
-
getFirstEncodedKey
Returns the first key argument in its byte-encoded representation.- Returns:
- the first key argument in its byte-encoded representation or
null.
-
encode
Encode theCommandArgsand write the arguments to theByteBuf.- Parameters:
buf- the target buffer.
-