EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Redis Tutorial RedisJSON
Secondary Sidebar
Redis Tutorial
  • Redis
    • Redis Pubsub
    • Redis GUI
    • Redis Database
    • Redis Get All Keys
    • Redis TTL
    • Redis EXPIRE
    • Redis Version
    • Redis EXPIRE
    • Redis List
    • Redis CLI Commands
    • Redis HSET
    • Redis FLUSHDB
    • Redis Key
    • Redis Persistence
    • Redis FLUSHALL
    • Redis pipeline
    • Redis SADD
    • Redis ZADD
    • Redis ZSET
    • Redis Get
    • Redis Replication
    • Redis Delete All Keys
    • Redis Use Cases
    • Redis HMSET
    • Redis Transactions
    • Redis Monitor
    • Redis HGET
    • Redis SETEX
    • Redis Rails
    • RedisJSON
    • Redis Get Key
    • Redis Auth
    • Redis gem
    • Redis Key Count
    • RedisTimeSeries
    • Redis Timeout
    • Redis LPUSH
    • Redis Architecture
    • Redis API
    • Redis Message Queue
    • Redis RPUSH
    • Redis Protocol
    • Redis Data Types
    • Redis Namespace
    • Redis ZRANGE
    • Redis Master Slave
    • Redis Memory Usage
    • Redis WATCH
    • Redis URL
    • Redis Key Value
    • Redis INCR
    • Redis EXISTS
    • Redis INFO
    • Redis HMGET
    • Redis Operator
    • Redis NOAUTH Authentication Required
    • Redis LRANGE
    • Redis RDB
    • Redis TLS
    • Redis HDEL
    • Redis WebSocket
    • Redis HGETALL
    • Redis GETSET
    • Node-RED WebSocket

RedisJSON

Introduction to RedisJSON

The RedisJSON module provides redis support. RedisJSON, like the other data types in the redis database, stores and retrieves json values. It also works with redis search to query and index json documents. It fully supports the json standard. We can update and select elements using RedisJSON path syntax.

RedisJSON

Key Takeaways

  • This module provides support in Redis; this module adds json as a native json data type.
  • This module will extend the client of node redis for including the functions which we have defined in RedisJSON command.

What is RedisJSON?

RedisJSON allows us to create indexes on json documents and uses real-time indexing, allowing us to quickly query the indexed documents. The indexes query our data at lightning speed, performing complex aggregations on the property’s numeric ranges and geographical distances. It will support full-text indexing as well as stemming-based queries.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

It is providing a rich query language which was performing complex structured queries and text searches. The RedisJSON enterprise and enterprise cloud will offer to scale up and scale down the RedisJSON across the entire cluster. It is allowing us to grow the indexes in billions of documents and it is situated in a number of servers. The RedisJSON module is adding support for the data structure of json for the database of redis.

How to Install RedisJSON?

In the below example we are building the RedisJSON by using the source code as follows:

1. In the first step we are downloading the repository from git. We are building after downloading the repository. We are installing the RedisJSON by using git as follows.

Command:

git clone --recursive ….git

Output:

RedisJSON - downloading the repository

2. After downloading the package now in this step, we are installing the dependencies as follows.

Command:

# ./sbin/setup

Output:

RedisJSON - installing the dependencies

3. After installing the dependencies now in this step we are building the same by using the make build command as follows.

Command:

# make build

Output:

RedisJSON - make build command

4. After installing the dependencies now in this step we are loading the module of redis as follows.

Command:

# ./deps/readies/bin/getredis

Output:

RedisJSON - loading the module

5. After loading the module now in this step we are running the module by using json as follows.

Code:

# make run

Output:

RedisJSON - Running the module

Uses of RedisJSON

We need to start the redis server by using json module. In the below example, we can see that we have started the redis server by using json module.

Starting RedisJSON Server

After starting the redis by using json module now in this step we are login into the redis cli as follows.

Command:

# redis-cli

Output:

login into the redis cli

After login into the redis cli now in this step we are using the JSON command to use in redis. In the below example, we can see that we are using set command with json as follows. We are defining color using json set command as follows.

Command:

JSON.SET color $ '"BLUE"'

Output:

RedisJSON - set command with json

In the below example, we can see that we are using the get command with json as follows. We are retrieving the value which we have set using json set command.

Command:

JSON.GET color $

Output:

RedisJSON - get command

After defining the get command now in the below example we are defining the type of value which we have passed in the set method.

Command:

JSON.TYPE color $

Output:

RedisJSON - type of value

Below we are using string operation on value which we have provided with the set command, in the below example we are using STRLEN, STRAPPEND, and GET commands as follows.

Command:

JSON.STRLEN color $
JSON.STRAPPEND color $ '" (Red color)"'
JSON.GET color $

Output:

RedisJSON - string operation

RedisJSON Types

The type of json is defined as the type we are using to use the value or to retrieve the value. We defined the RedisJSON types with the json type command. In the following example, we define the value in integer format, so the type of RedisJSON is as follows. Because we defined an integer value, we can see that the type of value is an integer.

Command:

JSON.SET number $ '15'
JSON.TYPE number $

Output:

RedisJSON - value in integer format

In the following example, we define the value in string format, so the type of RedisJSON is as follows. Because we defined an integer value, we can see that the type of value is string.

Command:

JSON.SET col $ '"White"'
JSON.TYPE col $

Output:

value in string format

If we define a type as a floating point number, RedisJSON will display it in number formats. In the following example, we defined the value as 10.5 as follows.

Command:

JSON.SET number $ '10.5'
JSON.TYPE number $

Output:

displaying in number formats

RedisJSON Path Syntax

RedisJSON will introduce path support in json. The json path query resolves the multiple locations into the document of JSON.

Syntax:

JSON.SET(COMMAND) KEY ‘$.val[“ “]’

Below is the syntax element of RedisJSON path as follows. It contains the element which we have defined in RedisJSON path.

  • $ – This is defined as RedisJSON path is starting.
  • [] or . (dot) – It will select the child element.
  • .. – This is recursively defining the documents of JSON.
  • * – This is used to return all the elements.
  • [] – This is subsequent operations or defining the array elements.
  • [,] – This is used to define the multiple elements in it.
  • [start:end:step] – This will define the array where it is starting and ending.
  • ?() – This defines filter for object array json.
  • () – It will define the expression of the script.
  • @ – It will define the current element.

Examples of RedisJSON

Given below are the examples mentioned:

Example #1

The below example shows by using JSON we are multiplying the number as follows.

Command:

JSON.SET redis_num $ 10
JSON.NUMINCRBY redis_num $ 15
JSON.NUMINCRBY redis_num $ 10.5
JSON.NUMINCRBY redis_num $ -10.5
JSON.NUMINCRBY redis_num $ 25

Output:

multiplying the number

Example #2

In the below example, we are using set and get method with redis as follows.

Command:

JSON.SET redis_color $ '"Black"'
JSON.SET redis_color

Output:

using set and get method

Example #3

In the below example, we are setting the object. In json objects will contain their own commands as follows.

Command:

JSON.SET obj $ '{"stud_name":"ABC","stud_no":1,"stud_addr": "Pune"}'
JSON.OBJLEN obj $
JSON.OBJKEYS obj $

Output:

Setting the object

Conclusion

RedisJSON enterprise and enterprise cloud will provide the ability to scale up and scale down across the entire cluster. The module provides support in redis. It stores, updates, and retrieves json values in the redis database in the same way that other data types in the redis database do.

Recommended Articles

This is a guide to RedisJSON. Here we discuss the introduction, how to install RedisJSON? types and examples respectively. You may also have a look at the following articles to learn more –

  1. Redis Delete All Keys
  2. Redis Use Cases
  3. Redis ZADD
  4. Redis pipeline
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more