Interface JsonOperations<K>

Type Parameters:
K - the Redis key type.
All Known Subinterfaces:
RedisJsonOperations<K>
All Known Implementing Classes:
RedisJsonTemplate

public interface JsonOperations<K>
Fluent operations for storing JSON documents in Redis and accessing their values.

Use the value(Object), array(Object), string(Object), and bool(Object) entry points to select a key and configure an operation. Commands operate on the document root unless a JSON path is selected. The following example stores a document and reads one of its properties:

operations.value("user").set(new Person("John", "Doe"));
String firstName = operations.value("user").path("$.firstName").get().as(String.class);

JSON paths follow the RedisJSON version 2 syntax. Commands returning a List of per-path results preserve the order of the matches. Unless specified otherwise, a null element indicates an incompatible JSON type.

Operations execute when a command method such as JsonOperations.JsonKeySupport.get() or JsonOperations.JsonSet.set(Object) is called. Key and path specifications are immutable and can be reused. Use JsonOperations.JsonResult to access a read result as JSON or deserialize it into a Java object.

Since:
4.2
Author:
Mark Paluch, Yordan Tsintsov, Moritz Halbritter
See Also:
  • Method Details

    • array

      Start building a JSON array operation for the given key.
      Parameters:
      key - the Redis key.
      Returns:
      a spec for specifying the array operation.
    • bool

      Start building a JSON boolean operation for the given key.
      Parameters:
      key - the Redis key.
      Returns:
      a spec for specifying the boolean operation.
    • string

      Start building a JSON string operation for the given key.
      Parameters:
      key - the Redis key.
      Returns:
      a spec for specifying the string operation.
    • value

      Start building a JSON value operation for the given key.
      Parameters:
      key - the Redis key.
      Returns:
      a spec for specifying the value operation.
    • get

      default JsonOperations.JsonResult get(K key)
      Retrieve the JSON value for the given key.
      Parameters:
      key - the Redis key.
      Returns:
      the JSON value for the given key.
    • set

      default Boolean set(K key, Object value)
      Set the key to a JSON value.
      Parameters:
      key - the Redis key.
      value - the value to write.
      Returns:
      true if the value was written; false otherwise.
    • paths

      default JsonOperations.JsonPathResult paths(K key, String... paths)
      Read the values at the given paths for a single key in one JSON.GET command.

      See paths(Object, Collection) for supported path forms and result mapping.

      Parameters:
      key - the Redis key.
      paths - the paths to read, must not be empty or contain duplicates.
      Returns:
      the combined result for the requested paths.
      Throws:
      IllegalArgumentException - if the paths violate the requirements of paths(Object, Collection).
      See Also:
    • paths

      Read the values at the given paths for a single key in one JSON.GET command.

      Paths may be property paths such as "name" and "address.city", or JSONPath expressions such as "$.name". All paths in a request must use the same form.

      The result supports deserialization into an object with one property per requested path. Property names correspond to the supplied path strings. Use JsonOperations.JsonPathResult.path(String) to access the matches for an individual path.

      Parameters:
      key - the Redis key.
      paths - the paths to read, must not be empty or contain duplicates.
      Returns:
      the combined result for the requested paths.
      Throws:
      IllegalArgumentException - if the paths are empty, contain duplicates, mix property paths with JSONPath expressions, or include a path omitted from the Redis response.
      See Also:
    • values

      default JsonOperations.JsonAtKeysSpec values(K key)
      Start building a JSON read operation for the given key.
      Parameters:
      key - the Redis key.
      Returns:
      a specification for selecting the path to read.
      See Also:
    • values

      default JsonOperations.JsonAtKeysSpec values(K key, K... additionalKeys)
      Start building a JSON read operation for the given keys.
      Parameters:
      key - the Redis key.
      additionalKeys - the additional Redis keys.
      Returns:
      a specification for selecting the path to read.
      See Also:
    • values

      Start building a JSON read operation for the given keys.
      Parameters:
      keys - the Redis keys.
      Returns:
      a specification for selecting the path to read.
      See Also: