Redis Stack RedisJSON Module: Commands, JSONPath Syntax, and Usage Examples
This article introduces Redis Stack’s RedisJSON module, explains its JSONPath syntax, details the full set of JSON commands for handling various data types, provides practical code examples, and highlights how RedisJSON enables Redis to function as a document, full‑text, and vector search database.
Redis is widely used as a key‑value cache, but its developers have extended it into a real‑time data platform called Redis Stack, which bundles several modules such as RedisJSON , RediSearch , RedisTimeSeries , and RedisBloom to support JSON data, full‑text and vector search, time‑series, and probabilistic calculations.
RedisJSON adds native JSON support to Redis, treating JSON as a first‑class data type alongside strings, lists, sets, and hashes. The module uses JSONPath syntax to address specific elements within a JSON document.
The JSONPath syntax includes operators like $ for the root, . or [] for child elements, .. for recursive descent, * as a wildcard, index brackets [] , union [,] , slice [start:end:step] , filter ?() , script expression () , and @ for the current element.
RedisJSON provides a comprehensive set of commands:
General commands: JSON.SET , JSON.GET , JSON.MERGE , JSON.FORGET / JSON.DEL , JSON.CLEAR , JSON.TYPE .
Array commands: JSON.ARRAPPEND , JSON.ARRINDEX , JSON.ARRINSERT , JSON.ARRLEN , JSON.ARRPOP , JSON.ARRTRIM .
Object commands: JSON.OBJKEYS , JSON.OBJLEN .
Number command: JSON.NUMINCRBY .
String commands: JSON.STRAPPEND , JSON.STRLEN .
Boolean command: JSON.TOGGLE .
Debug commands: JSON.DEBUG , JSON.DEBUG MEMORY .
Batch commands: JSON.MGET , JSON.MSET .
Deprecated commands: JSON.RESP , JSON.MUMMULTIBY .
Example usage demonstrates setting JSON values, merging objects, retrieving specific paths, manipulating arrays, incrementing numbers, appending strings, toggling booleans, and checking memory usage, all via the Redis CLI.
In summary, RedisJSON equips Redis with robust JSON handling, allowing Redis Stack to serve as a document database, a full‑text search engine, or a vector search engine, and the article provides a foundation for further exploration of Redis Stack’s other modules.
System Architect Go
Programming, architecture, application development, message queues, middleware, databases, containerization, big data, image processing, machine learning, AI, personal growth.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.