Command builders for RedisJSON operations (Redis 8+ / RedisJSON module).
Provides pure functions for storing, retrieving, and manipulating JSON documents inside Redis. Supports the full JSON.* command set including object, array, string, and numeric operations.
All path arguments default to "$" (JSONPath root). Values passed to
mutating functions are automatically encoded via JSON.encode!/1 unless
the raw: true option is given.
Every function returns a command list for use with Redis.command/2 or
Redis.pipeline/2.
Examples
# Store a JSON document
Redis.command(conn, JSON.set("user:1", %{name: "Alice", age: 30}))
# Read specific paths from a document
Redis.command(conn, JSON.get("user:1", paths: ["$.name", "$.age"]))
# Append elements to a nested array
Redis.command(conn, JSON.arrappend("user:1", ["reading", "hiking"], "$.hobbies"))
Summary
Functions
JSON.ARRAPPEND — append values to an array.
JSON.ARRINDEX — find index of a value in an array.
JSON.ARRINSERT — insert values at an index.
JSON.ARRLEN — get array length.
JSON.ARRPOP — pop from an array (default: last element).
JSON.ARRTRIM — trim an array to [start, stop].
JSON.CLEAR — clear arrays/objects at a path (set to empty).
JSON.DEL — delete a path from a key.
JSON.GET — get JSON value(s) at one or more paths.
JSON.MERGE — merge a JSON value into an existing key.
JSON.MGET — get a path from multiple keys.
JSON.NUMINCRBY — increment a number at a path.
JSON.NUMMULTBY — multiply a number at a path.
JSON.OBJKEYS — get object keys at a path.
JSON.OBJLEN — get number of keys in an object.
JSON.SET — set a JSON value at a path.
JSON.STRAPPEND — append to a string at a path.
JSON.STRLEN — get string length at a path.
JSON.TOGGLE — toggle boolean at a path.
JSON.TYPE — get the JSON type at a path.
Functions
JSON.ARRAPPEND — append values to an array.
JSON.ARRINDEX — find index of a value in an array.
@spec arrinsert(String.t(), non_neg_integer(), [term()], String.t()) :: [String.t()]
JSON.ARRINSERT — insert values at an index.
JSON.ARRLEN — get array length.
JSON.ARRPOP — pop from an array (default: last element).
@spec arrtrim(String.t(), non_neg_integer(), integer(), String.t()) :: [String.t()]
JSON.ARRTRIM — trim an array to [start, stop].
JSON.CLEAR — clear arrays/objects at a path (set to empty).
JSON.DEL — delete a path from a key.
JSON.GET — get JSON value(s) at one or more paths.
JSON.get("key")
JSON.get("key", paths: ["$.name", "$.age"])
JSON.MERGE — merge a JSON value into an existing key.
JSON.MGET — get a path from multiple keys.
JSON.NUMINCRBY — increment a number at a path.
JSON.NUMMULTBY — multiply a number at a path.
JSON.OBJKEYS — get object keys at a path.
JSON.OBJLEN — get number of keys in an object.
JSON.SET — set a JSON value at a path.
Value is auto-encoded to JSON. Pass a raw JSON string with raw: true.
JSON.set("key", %{a: 1})
JSON.set("key", %{a: 1}, path: "$.nested")
JSON.set("key", ~s({"a":1}), raw: true)
JSON.set("key", %{a: 1}, nx: true) # only set if doesn't exist
JSON.set("key", %{a: 1}, xx: true) # only set if exists
JSON.STRAPPEND — append to a string at a path.
JSON.STRLEN — get string length at a path.
JSON.TOGGLE — toggle boolean at a path.
JSON.TYPE — get the JSON type at a path.