RedisJSON is a Redis module that lets you store JSON documents in Redis. It is a JSON data type for Redis that lets you to fetch or modify a specific element in the document tree, without retrieving (or internally even parsing) the document. Its Python client even lets you store python dicts and convert them to JSON automatically.
The 'rejson-py' is a package that allows storing, updating and querying objects as JSON documents in a Redis database that is extended with the RedisJSON module. The package extends redis-py's interface with RedisJSON's API, and performs on-the-fly serialization/deserialization of objects to/from JSON.
Follow the steps below to get started with RedisJSON with Python:
Let us consider a simple JSON document structure:
Below is a python code to store the JSON document into Redis:
In the code above, we use JSON.GET to extract the JSON elements. Save the above file as "employee.py".
It's possible to fetch specific field within JSON element. Let us modify the above code and add "address" field as shown below:
In the above example, the code tries to fetch only the location under the address field.