Databases 10 min read

Mastering Redis Modules: From Basics to Practical RedisJSON Guide

This article explains what Redis Modules are, lists the most popular official modules, and provides a step‑by‑step tutorial on installing Redis, setting up RedisJSON, and using its commands for creating, reading, updating, and deleting JSON data.

Architecture & Thinking
Architecture & Thinking
Architecture & Thinking
Mastering Redis Modules: From Basics to Practical RedisJSON Guide

1 What is a Redis Module

Redis Module is an extension mechanism introduced in Redis 4.0 that allows users to add new data types and commands without recompiling Redis, enabling custom functionality across Redis versions.

Modules let you implement advanced features such as full‑text search, JSON storage, distributed locks, and time‑series data.

2 Common Redis Modules

The Redis project officially recommends the following modules:

2.1 RediSearch

A full‑text search engine supporting fast retrieval, secondary indexing, and complex queries.

2.2 RedisJSON

Provides native JSON support, allowing storage, update, and retrieval of JSON values directly in Redis.

2.3 RedisTimeSeries

A time‑series database module that stores multiple series accessible via standard Redis keys.

2.4 RedisGraph

Implements a graph database on top of Redis.

2.5 RedisBloom

Adds probabilistic data structures such as Bloom filters, Cuckoo filters, Count‑min sketch, Top‑K, and t‑digest.

2.6 RedisCell

Provides distributed rate‑limiting using the Generic Cell Rate Algorithm (GCRA).

2.7 RedisAI

Enables execution of deep‑learning and machine‑learning models within Redis, offering high‑performance inference.

3 Redis Module Practical Guide

3.1 Install Redis

Ensure Redis is installed before using any module. Follow the official installation guide at https://redis.io/docs/install/install-redis/.

3.2 Example: RedisJSON

3.2.1 Download RedisJSON

Download the latest release (v2.6.8) from the GitHub releases page.

3.2.2 Install

1. Obtain the module file

Create a module directory under the Redis installation path and place rejson.so there.

<code># cd /usr/local/soft/redis-6.2.6/
# mkdir module
# (copy rejson.so into module)</code>

2. Modify configuration

<code># cd ./module
# chmod +x rejson.so
# edit redis.conf to add:
loadmodule /usr/local/soft/redis-6.2.6/module/rejson.so
# restart Redis</code>

3.2.3 RedisJSON Operations

1. Write with JSON.SET

<code>JSON.SET &lt;key&gt; &lt;path&gt; &lt;json&gt; [NX|XX]</code>

key – target key

path – JSON path

json – JSON value

NX – set only if key does not exist

XX – set only if key exists

Example:

<code># Save two records
127.0.0.1:6379> JSON.SET user1 $ '{"name":"Brand","age":18,"sex":"1"}'
127.0.0.1:6379> JSON.SET user2 $ '{"name":"Candy","age":17,"sex":"0"}'</code>

2. Read with JSON.GET

<code>JSON.GET &lt;key&gt; [INDENT <string>] [NEWLINE <string>] [SPACE <string>] [path ...]</code>

Key – key to retrieve

INDENT, NEWLINE, SPACE – formatting options

path – optional JSON paths

<code># Get all data
127.0.0.1:6379> JSON.GET user1
'{"name":"Brand","age":18,"sex":"1"}'
# Get a specific field
127.0.0.1:6379> JSON.GET user1 name
"Brand"</code>

3. Batch read with JSON.MGET

<code>JSON.MGET &lt;key&gt; [key ...] &lt;path&gt;</code>

key – list of keys

path – common path for all keys

<code>127.0.0.1:6379> JSON.MGET user1 user2 $.name
1) "Brand"
2) "Candy"</code>

4. Delete with JSON.DEL

<code>JSON.DEL &lt;key&gt; [path]</code>

If path is omitted, the entire key is removed.

<code># Delete whole JSON
127.0.0.1:6379> JSON.DEL user1
(integer) 1
# Delete a field
127.0.0.1:6379> JSON.DEL user2 $.age
(integer) 1</code>

5. Additional commands

Numeric, string, array, and object operations are also supported (e.g., JSON.NUMINCRBY , JSON.ARRAPPEND , JSON.OBJKEYS , etc.). Refer to the official RedisJSON documentation for full syntax.

4 Summary

This article introduced Redis Modules, highlighted the officially recommended modules, and demonstrated a practical workflow for installing and using RedisJSON, covering common commands for creating, reading, updating, and deleting JSON data.

DatabaseRedisTutorialModulescommandsRedisJSON
Architecture & Thinking
Written by

Architecture & Thinking

🍭 Frontline tech director and chief architect at top-tier companies 🥝 Years of deep experience in internet, e‑commerce, social, and finance sectors 🌾 Committed to publishing high‑quality articles covering core technologies of leading internet firms, application architecture, and AI breakthroughs.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.