Interface Request


public interface Request
Builder for Redis requests that will be encoded according to the RESP protocol. RESP was introduced in Redis 1.2 and became the standard way for talking with the Redis server in Redis 2.0.

Redis protocol documentation states:

Clients send commands to a Redis server as a RESP Array of Bulk Strings.

So all non String/Bulk types will be encoded to Bulk for convenience.

Author:
Paulo Lopes
  • Method Summary

    Modifier and Type
    Method
    Description
    arg(boolean arg)
    Adds a boolean encoded to string
    default Request
    arg(byte arg)
    Adds a byte encoded to string
    arg(byte[] arg)
    Adds a byte array
    default Request
    arg(double arg)
    Adds a double encoded to string
    default Request
    arg(float arg)
    Adds a float encoded to string
    default Request
    arg(int arg)
    Adds a int encoded to string
    arg(long arg)
    Adds a long encoded to string
    default Request
    arg(short arg)
    Adds a short encoded to string
    arg(Buffer arg)
    Adds a String key argument
    default Request
    Adds a JsonArray argument, the encoding will serialize the json as value0, value1, ... valueN.
    default Request
    Adds a JsonObject argument, the encoding will serialize the json as key0, value0, key1, value1, ... keyN, valueN.
    default Request
    arg(String arg)
    Adds a String argument using UTF8 character encoding
    default Request
    arg(String arg, String enc)
    Adds a String using a specific character encoding argument
    static Request
    cmd(Command command)
    Creates a new request.
    static Request
    cmd(Command command, Object... args)
    Creates a new request only with simple types of arguments: Number, Boolean, String, byte[] or Buffer.
    Get the Command that is to be used by this request.
  • Method Details

    • cmd

      static Request cmd(Command command)
      Creates a new request. Requests can be reused to avoid GC.
      Parameters:
      command - the command to use
      Returns:
      a new request instance
    • cmd

      static Request cmd(Command command, Object... args)
      Creates a new request only with simple types of arguments: Number, Boolean, String, byte[] or Buffer. Other kinds of arguments throw an exception.

      This factory reduces the GC pressure as it allocates the arguments array with the right size.

      Parameters:
      command - the command to use
      args - the fixed list of arguments
      Returns:
      a new request instance
    • arg

      Request arg(byte[] arg)
      Adds a byte array
      Returns:
      self
    • arg

      default Request arg(String arg)
      Adds a String argument using UTF8 character encoding
      Returns:
      self
    • arg

      default Request arg(String arg, String enc)
      Adds a String using a specific character encoding argument
      Returns:
      self
    • arg

      Request arg(Buffer arg)
      Adds a String key argument
      Returns:
      self
    • arg

      Request arg(long arg)
      Adds a long encoded to string
      Returns:
      self
    • arg

      default Request arg(int arg)
      Adds a int encoded to string
      Returns:
      self
    • arg

      default Request arg(short arg)
      Adds a short encoded to string
      Returns:
      self
    • arg

      default Request arg(byte arg)
      Adds a byte encoded to string
      Returns:
      self
    • arg

      default Request arg(float arg)
      Adds a float encoded to string
      Returns:
      self
    • arg

      default Request arg(double arg)
      Adds a double encoded to string
      Returns:
      self
    • arg

      Request arg(boolean arg)
      Adds a boolean encoded to string
      Returns:
      self
    • arg

      default Request arg(JsonObject arg)
      Adds a JsonObject argument, the encoding will serialize the json as key0, value0, key1, value1, ... keyN, valueN. This is a non-optimized serialization and will just use the string encoding of the values for non buffers.
      Returns:
      self
      Throws:
      IllegalArgumentException - when values are null or of type JsonArray or JsonObject
    • arg

      default Request arg(JsonArray arg)
      Adds a JsonArray argument, the encoding will serialize the json as value0, value1, ... valueN. This is a non-optimized serialization and will just use the string encoding of the values for non buffers.
      Returns:
      self
      Throws:
      IllegalArgumentException - when values are null or of type JsonArray or JsonObject
    • command

      Command command()
      Get the Command that is to be used by this request.
      Returns:
      the command.