RedisJSON is the module that turns Redis into a JSON document store — native parsed JSON, JSONPath addressing, partial updates without rewriting the whole document, and the ability to feed RediSearch indexes for ad-hoc queries. It is part of Redis Stack and ships with every modern Redis Enterprise install. This article covers the data model, the commands you actually use day to day, and the operational caveats (memory, atomicity, cluster keying) of running it.
How to verify
# Confirm the module is loaded
redis-cli MODULE LIST | grep -i json
# Expected: ReJSON or json with a version string
# Module-aware health
redis-cli JSON.DEBUG MEMORY user:42
redis-cli JSON.OBJLEN user:42 '$'
redis-cli JSON.TYPE user:42 '$.address'
What’s happening
RedisJSON stores JSON in a parsed binary form, not as a string. That means JSON.SET user:42 $ '{"name":"Ada","cart":[1,2,3]}' writes a structured value that future commands can address by JSONPath, modify partially, and index. Compared to storing JSON as a Redis string and rewriting it on every change, you get:
- Partial updates.
JSON.ARRAPPEND user:42 $.cart 4mutates one field without sending or rewriting the whole document. - Path queries.
JSON.GET user:42 $.address.cityextracts a single value server-side. - Atomicity. Each command runs atomically against the document — no read-modify-write race.
- Type safety. The module enforces JSON types;
JSON.NUMINCRBYerrors on a string.
JSONPath in RedisJSON is the v2 dialect — $ is the document root, .field traverses, [*] matches all array entries, [?(@.price>10)] filters. The first call to a path that does not exist returns nil rather than an error, which is convenient for optional fields.
The cost is memory. A parsed JSON tree uses 2-5x the bytes of the equivalent JSON string — pointer overhead and per-node metadata. For documents under a few KB this is fine. For documents over 10 KB consider a different data model (Hash for flat structures, separate keys for arrays).
The procedure
-
Confirm RedisJSON is loaded. Redis Stack ships it. If you are running OSS Redis, load the module in
redis.conf:loadmodule /usr/lib/redis/modules/rejson.soRestart and verify with
MODULE LIST. -
Set a document and read it back.
redis-cli JSON.SET user:42 '$' \ '{"name":"Ada","age":35,"cart":[101,102],"address":{"city":"Toronto"}}' redis-cli JSON.GET user:42 redis-cli JSON.GET user:42 '$.name' -
Update a field without rewriting the whole document.
redis-cli JSON.SET user:42 '$.age' 36 redis-cli JSON.NUMINCRBY user:42 '$.age' 1 redis-cli JSON.STRAPPEND user:42 '$.name' '" Lovelace"' -
Append to an array atomically.
redis-cli JSON.ARRAPPEND user:42 '$.cart' 103 104 redis-cli JSON.ARRLEN user:42 '$.cart' -
Delete a sub-tree.
redis-cli JSON.DEL user:42 '$.address.postal_code' -
Index with RediSearch for query. Define a JSON-aware index that follows JSONPaths.
redis-cli FT.CREATE idx:users ON JSON PREFIX 1 user: SCHEMA \ '$.name' AS name TEXT SORTABLE \ '$.age' AS age NUMERIC \ '$.address.city' AS city TAG redis-cli FT.SEARCH idx:users '@city:{Toronto} @age:[30 40]' -
Bound memory. Monitor
JSON.DEBUG MEMORY <key>to detect documents that have grown beyond expectations and split them into separate keys if they trend over a few KB.
Common pitfalls
- Storing a 1 MB JSON document in RedisJSON because “Redis is fast” hides the fact that every read materializes the document; latency tracks document size. Split.
- A document spread across many keys via the cluster does not give you cross-document atomicity. If you need atomic updates across documents, hash-tag them onto the same slot:
user:{42}:profileanduser:{42}:settings. JSON.SETwith no condition (NX/XX) overwrites blindly. UseJSON.SET key path value XXto only update if the path exists, orNXto only create.- RediSearch indexes on JSON re-index the affected document on every change. A high-write-rate document with a large index is expensive — profile with
FT.PROFILE. - Compression: RedisJSON does not compress the in-memory representation. If you have many similar documents, compression in the application before storing as a string sometimes saves more memory than parsed JSON gains in addressability.
In the engagements we run, RedisJSON usually shows up alongside RediSearch as the document layer behind admin dashboards and short-TTL profile caches. We operate the Redis Stack under Managed Operations — module-aware backups, version pinning, and an upgrade path that does not lose indexes on restart. Clients also lean on RediSearch on the same documents for query.