JSON Documents
Store structured documents and update individual fields through RedisJSON commands. Swytch includes the JSON.* command
family in its Redis server; you do not need to install a separate module.
JSON.SET product:42 $ '{"name":"tea","stock":10,"tags":["drink"]}'
JSON.GET product:42 $
JSON.NUMINCRBY product:42 $.stock -1
JSON.ARRAPPEND product:42 $.tags '"sale"'
JSON.GET product:42 $.stock
The final read returns [9]. JSONPath expressions beginning with $ return matching values using array semantics, even
when one value matches. Legacy paths such as .stock have different reply shapes; use the path style your client
expects.
Use JSON.SET to replace a document or a selected value, JSON.NUMINCRBY for numeric updates, and the array commands
to modify collections. These commands avoid fetching and rewriting an entire document in application code.
A JSON document is a distinct value type. To access a document stored with JSON.SET, use JSON.GET. A JSON string
stored with ordinary SET is still a string; it does not become a RedisJSON document automatically.
JSON documents use the same local and distributed key model as other structures. Local durability can restore synced resident document history after a restart on the same disk. Choose tiering for retention beyond local eviction or disk loss.
See the JSON command reference for the supported command family. RedisJSON support is separate
from the Lua cjson library; review scripting compatibility when migrating scripts.