Exemple #1
0
 /**
  * Read an "array" response from the server and convert each entry to a string using the default
  * string representation ({@link String#valueOf}), throwing an exception if the result is not an
  * array type.
  *
  * <p>Null values in the array will be preserved as {@code null}s.
  *
  * <p>This is a blocking operation.
  *
  * @return The response as a {@code List} of strings
  * @throws BajaTypeMismatchException If the response was not an array
  * @throws BajaResourceException If there was an error reading from the stream
  * @throws BajaProtocolErrorException If the server responded with an error result
  */
 public List<String> readStringArray() {
   verifyResponseType(Collections.singleton(RespType.ARRAY));
   return IOFunction.runCommand(() -> parser.readArray(inputStream))
       .stream()
       .map(i -> i == null ? null : String.valueOf(i))
       .collect(Collectors.toList());
 }
Exemple #2
0
  /**
   * Read any type of response from the server, throwing an exception if the result is an Redis
   * error.
   *
   * <p>This might be useful for Redis commands that return different types based on the arguments
   * supplied to them. In this case, the caller will have to inspect the type of the result
   * afterwards to determine the appropriate course of action.
   *
   * <p>This is a blocking operation.
   *
   * @return The response as an Object
   * @throws BajaResourceException If there was an error reading from the stream
   * @throws BajaProtocolErrorException If the server responded with an error result
   */
  public Object readAnyType() {
    final Set<RespType> expected = new HashSet<>();
    expected.add(RespType.BULK_STRING);
    expected.add(RespType.SIMPLE_STRING);
    expected.add(RespType.INTEGER);
    expected.add(RespType.ARRAY);

    final RespType type = verifyResponseType(expected);
    switch (type) {
      case BULK_STRING:
        return IOFunction.runCommand(() -> parser.readBulkString(inputStream));
      case SIMPLE_STRING:
        return IOFunction.runCommand(() -> parser.readSimpleString(inputStream));
      case INTEGER:
        return IOFunction.runCommand(() -> parser.readLong(inputStream));
      case ARRAY:
        return IOFunction.runCommand(() -> parser.readArray(inputStream));
    }

    throw new IllegalStateException("Got unexpected result type " + type);
  }
Exemple #3
0
 /**
  * Read an "array" response from the server, throwing an exception if the result is not an array
  * type.
  *
  * <p>It is the responsibility of the caller to know the expected types of each entry in the list.
  *
  * <p>This is a blocking operation.
  *
  * @return The response as a {@code List} of objects
  * @throws BajaTypeMismatchException If the response was not an array
  * @throws BajaResourceException If there was an error reading from the stream
  * @throws BajaProtocolErrorException If the server responded with an error result
  */
 public List<Object> readArray() {
   verifyResponseType(Collections.singleton(RespType.ARRAY));
   return IOFunction.runCommand(() -> parser.readArray(inputStream));
 }