Module lettuce.core

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 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 Details

  • Constructor Details

    • CommandArgs

      public CommandArgs​(RedisCodec<K,​V> codec)
      Parameters:
      codec - Codec used to encode/decode keys and values, must not be null.
  • Method Details

    • 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 be null.
      Returns:
      the command args.
    • addKeys

      @SafeVarargs public final CommandArgs<K,​V> addKeys​(K... keys)
      Add multiple key arguments.
      Parameters:
      keys - must not be null.
      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 be null.
      Returns:
      the command args.
    • addValues

      @SafeVarargs public final CommandArgs<K,​V> addValues​(V... values)
      Add multiple value arguments.
      Parameters:
      values - must not be null.
      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 be null.
      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 a CommandKeyword argument. The argument is represented as bulk string.
      Parameters:
      keyword - must not be null.
      Returns:
      the command args.
    • add

      public CommandArgs<K,​V> add​(CommandType type)
      Add a CommandType argument. The argument is represented as bulk string.
      Parameters:
      type - must not be null.
      Returns:
      the command args.
    • add

      public CommandArgs<K,​V> add​(ProtocolKeyword keyword)
      Add a ProtocolKeyword argument. The argument is represented as bulk string.
      Parameters:
      keyword - the keyword, must not be null
      Returns:
      the command args.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toCommandString

      public String toCommandString()
      Returns a command string representation of CommandArgs with annotated key and value parameters. args.addKey("mykey").add(2.0) will return key<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 the CommandArgs and write the arguments to the ByteBuf.
      Parameters:
      buf - the target buffer.