Introduction
RedisJSON fully supports the JSON Data Interchange Standard (ECMA-404).
Any of the valid values does refer to as a JSON Value. A JSON Array or a JSON object is use as a Container. A JSON Scalar is a number, string, or literal in JSON (JSON False, JSON True, or JSON Null).
RedisJSON API
Details on a module's commands, such as JSON, can be filtered for a single module or management. The syntax for the controls includes the details, where
- JSON, for example, has uppercase command and subcommand names.
-
INDENT or SET
Optional arguments, such as [index], are included in square brackets. - Three-period characters indicate additional optional arguments.
The name of a key is usually the first argument in commands. If the path does not supply, it is considered the root.
The path's time complexity is not included in the command's time complexity. A value's size, commonly indicated by the letter N, is:
- One for scalar values.
- The total length of all the things in a container.
Commands JSON
JSON.ARRAPPEND key [path] value [value ...]
Available in Redis Stack
The complexity of time: When the path do evaluate to a single value, O(1) is used; when the path is evaluated to several values, O(N) is used.
After the last element in the array, append the JSON values to it.
JSON.ARRLEN key [path]
Available in Redis Stack
The complexity of time: O(1) where the path do evaluate to a single value, O(N) where the approach is considered to multiple values, where N is the size of the key
Reports the length of the JSON Array at the path in key.
Path defaults to root if not provided. Returns null if the key or path does not exist.
JSON.TYPE key [path]
Available in Redis Stack
The complexity of time: O(1) when the path do evaluate to a single value, O(N) when the approach is considered to multiple values, where N is the size of the key
Reports the type of JSON value at the path.
Path defaults to root if not provided. Returns null if the key or path does not exist.
JSON.STRAPPEND key [path] value
Available in Redis Stack
The complexity of time: When the path do evaluate to a single value, O(1) is used; when the approach is assessed to several matters, O(N) is used.
The JSON-string values do append to the path string.
If no path is specified, the root is assumed.
JSON.TOGGLE key [path]
Available in Redis Stack
The complexity of time: O(1) when the path do evaluate to a single value, O(N) when the approach is considered to multiple values, where N is the size of the key
Toggle a boolean value stored at the path.
[] element for JSON values matching the path, which are not boolean.
Frequently asked questions
Is it possible to store JSON in Redis?
JSON can be stored in Redis as a single string in a dedicated key (or as a member/value of a set/list) or as a hash structure. If you look at the Friendlier hash commands section of the node Redis docs, you'll notice that it provides some practical techniques for processing JSON-based data.
What are the Redis commands?
To launch the Redis client, open a terminal and type Redis-client. It will establish a connection to your local server, from which you can issue any command. In the example above, we connect to a Redis server running on the local machine and run the command PING to see if the server is up and running.
Is it possible to query Redis?
Redis is a NoSQL database that does not require SQL or structured query language. Instead, Redis comes with its own data management and access commands set.
How can I see what's in the Redis cache?
All of the contents of a Redis key will open in a new editing tab when you click on its name. Clicking on a collection type Redis key reveals the individual elements under the key phrase. When you click a particular part, the contents of that element will appear in a new editing tab.
How does the Redis database function?
Redis uses a primary-replica architecture that allows for asynchronous data replication across many replica servers. It improves read performance and provides for faster recovery when the primary server goes down.
Conclusion
This article has gone through a commands overview for RedisJSON. RedisJSON allows you to save, update, and retrieve JSON values in Redis the same way you would do with any other data type. RedisJSON also integrates with RediSearch, allowing you to index and query JSON documents. If you would like to learn more, check out our articles in Library, where you can find everything about Redis, Interview Experiences, and other guided paths
Attempt our Online Mock Test Series on Coding Ninjas Studio now!
Ninja, have a great time learning.




