Skip to content
LOCEN/Ontario · CAStandbyOK/--:--:--EST
M4M4RK_YUportfolio
  • Projects
    ProjectsOverview
    • WorkSelected case studies and write-ups
    • GamesPlayable prototypes and game-dev logs
  • Gallery
    GalleryOverview
    • ArchivePhoto collections and visual experiments
    • ShopPrints, posters, and one-off objects
  • Logs
    LogsOverview
    • BlogLong-form devlogs and field notes
    • NotesShort observations, links, snippets
  • Resources
    ResourcesOverview
    • Tools38 in-browser developer utilities
    • LinksDaily-use dev and design bookmarks
  • About
  • Contact
中文

syndicated · dev.to / @markyu

RedisJSON: Enhancing JSON Data Handling in Redis

Introduction JSON has become the standard format for data exchange in modern...

Published
May 24 '24
·
Reading time
4 min read
·
Reactions
20
·
Comments
1
redisjsoncachedata
View on dev.toDiscuss

Introduction

Image description

JSON has become the standard format for data exchange in modern applications. However, traditional relational databases may face performance challenges when handling JSON data. To address this issue, Redis introduced the RedisJSON module, which allows developers to store, query, and manipulate JSON data directly within the Redis database. This article will delve into RedisJSON's working principles, key operations, performance advantages, and usage scenarios.

Table of Contents

  1. Introduction to RedisJSON
  2. How RedisJSON Works
  3. Installing RedisJSON
  4. Basic Operations with RedisJSON
    • Storing JSON Data
    • Retrieving JSON Data
    • Getting JSON Data Type
    • Modifying JSON Data
    • Deleting JSON Data
    • Adding or Updating JSON Fields
    • Adding Elements to a JSON Array
    • JSONPath Queries
    • Getting JSON Array Length
    • Retrieving All Keys from a JSON Object
    • Deleting Fields in JSON
    • Complex Queries
  5. Performance Advantages
  6. Use Cases
  7. Conclusion

1. Introduction to RedisJSON

RedisJSON is an extension module for Redis that provides native support for JSON data. With RedisJSON, developers can store JSON documents in Redis and perform efficient queries and operations on them. This module simplifies data processing workflows and significantly enhances the performance of JSON data handling.

2. How RedisJSON Works

Data Storage Format

RedisJSON stores data in an optimized binary format rather than simple text. This binary format allows for fast serialization and deserialization of JSON data, improving read and write performance.

Serialization and Deserialization

Before storing data in Redis, JSON data is serialized into a compact binary string. When reading data, this binary string is deserialized back into its original JSON format for easy use by applications.

Internal Data Structure

RedisJSON uses a tree-like structure, known as a Rax tree (Redis tree), to manage JSON data. This ordered dictionary tree allows for efficient key sorting and quick insertion, deletion, and lookup operations.

Query and Operation Optimization

RedisJSON supports JSONPath syntax for complex queries, enabling developers to filter and sort JSON data efficiently. All operations on JSON data are atomic, ensuring data consistency and integrity in high-concurrency environments.

Integration with Redis Ecosystem

RedisJSON seamlessly integrates with other Redis features and tools, such as transactions, pub/sub, and Lua scripting, providing a comprehensive solution for managing JSON data.

Performance Characteristics

Despite adding support for JSON data, RedisJSON maintains Redis's high performance. Optimized internal representation and efficient query algorithms ensure fast response times even with large datasets.

3. Installing RedisJSON

Prerequisites

Ensure that Redis is installed with a version of 6.0 or higher.

Downloading RedisJSON Module

Download the RedisJSON module from the Redis website or GitHub repository. Choose the version suitable for your operating system.

Loading RedisJSON Module

In the Redis configuration file (redis.conf), add a line to load the RedisJSON module using the loadmodule directive, followed by the module file path.

Example:

loadmodule /path/to/module/rejson.so

Verifying Installation

Start the Redis server and ensure there are no errors. Connect to the Redis server using the redis-cli tool and run MODULE LIST to verify that RedisJSON is loaded successfully.

4. Basic Operations with RedisJSON

Storing JSON Data

Use JSON.SET to store JSON data.

JSON.SET user $ '{"name":"HuYiDao","age":18}'

Retrieving JSON Data

Use JSON.GET to retrieve JSON data.

JSON.GET user

Getting JSON Data Type

Use JSON.TYPE to get the type of JSON data.

JSON.TYPE user

Modifying JSON Data

Use JSON.NUMINCRBY to modify numeric fields in JSON data.

JSON.NUMINCRBY user $.age 2

Deleting JSON Data

Use the DEL command to delete a key storing JSON data.

DEL user

Adding or Updating JSON Fields

Use JSON.SET with a path to add or update fields in a JSON object.

JSON.SET user $.address '{"city": "Beijing", "country": "China"}' NX

Adding Elements to a JSON Array

Use JSON.ARRAPPEND to add elements to a JSON array.

JSON.SET user $.hobbies '["reading"]'
JSON.ARRAPPEND user $.hobbies '"swimming"'

JSONPath Queries

Use JSONPath syntax to query JSON data.

JSON.GET user '$.name'

Getting JSON Array Length

Use JSON.OBJLEN to get the length of a JSON array.

JSON.OBJLEN user $.hobbies

Retrieving All Keys from a JSON Object

Use JSON.OBJKEYS to get all keys in a JSON object.

JSON.OBJKEYS user

Deleting Fields in JSON

Use JSON.DELPATH to delete specific fields in a JSON object.

JSON.DELPATH user $.address

Complex Queries

Use JSON.QUERY for advanced querying.

JSON.QUERY user '$[?(@.city=="Beijing")]'

5. Performance Advantages

RedisJSON offers several performance advantages:

  • In-Memory Storage: Storing data in memory ensures fast read and write speeds, outperforming traditional relational databases.
  • Tree Structure Storage: The tree structure enables quick access to sub-elements, enhancing query and operation efficiency.
  • Atomic Operations: All operations on JSON data are atomic, ensuring data consistency and preventing conflicts in concurrent environments.

6. Use Cases

RedisJSON is ideal for applications requiring real-time performance, such as:

  • Content Management Systems: Efficiently store and retrieve complex content structures and metadata.
  • Product Catalogs: Manage and search product attributes and SKU combinations effectively.
  • Mobile Applications: Synchronize data across client applications in real-time.
  • Session Management: Manage user session data efficiently in web applications.

Conclusion

RedisJSON provides a powerful solution for directly storing, querying, and manipulating JSON data within Redis. By leveraging RedisJSON's capabilities, developers can efficiently handle complex JSON data structures and meet the diverse needs of modern applications. Whether for content management, product catalogs, or mobile app development, RedisJSON offers a flexible and high-performance data storage and processing solution.

By understanding and utilizing RedisJSON, developers can take full advantage of Redis's speed and efficiency while working with JSON data.


References:

  • RedisJSON Documentation
  • GitHub Repository for RedisJSON
  • Redis Labs: RedisJSON Module

Related reading

database

The True Cost of Poor Data Quality: Why It Matters and How to Improve It

In today’s fast-paced, data-driven world, businesses have more access to data than ever before....

ipaddresses

How to Determine the Network Address from a Known IP Address

Ever wondered how devices communicate within a network? Or perhaps you've come across terms like "IP...

java

Advanced Java: Simplifying Object Property Copy and Manipulation with BeanUtil

In Java programming, the BeanUtil utility class is a powerful and convenient tool for simplifying the...

originally published

This post first ran on dev.to. Comments and reactions live there.

Continue on dev.to
PreviousKey Considerations for Effective Database Table DesignIntroduction In database design, the structure of tables is a critical element that...
Back to archive
NextAdvanced Java: Simplifying Object Property Copy and Manipulation with BeanUtilIn Java programming, the BeanUtil utility class is a powerful and convenient tool for simplifying the...
Back to archive
open channel·say hi anytime · 2026
--:--:--EST
get in touch

Saw something here?Tell me about it.

It's a portfolio, not a service · but I read every note — drop a line if anything here resonated, or just to say hi.

Start a conversation

Newsletter

Get the occasional dispatch

Notes and logs from m4rkyu.com — short, dated, no noise. Unsubscribe anytime.

Work

Production builds, games, and visual archives.

  • Projects
  • Games
  • Archive
  • Logs

Resources

Daily-use tools and a personal link library.

  • Search
  • Latest
  • Tools
  • Links
  • Notes
  • Topics
  • RSS
  • JSON feed
  • Shop

Studio

Background, contact, and channels for collaboration.

  • About
  • Contact
  • Changelog
  • Colophon
  • Resumepending

Socials

Find me on the usual feeds.

  • Facebooksoon
  • Instagramsoon
  • YouTubesoon
  • LinkedInsoon
M4RKYUM4RKYUM4RKYUM4RKYUM4RKYUM4RKYUM4RKYUM4RKYU
Crafted since 2024
ZhenXiao Mark YuZhenXiao Mark Yu
© 2026 ZhenXiao Mark Yu·Ontario, Canada
  • Email
  • GitHub
  • dev.to
  • LinkedIn (soon)
  • Twitter / X (soon)
  • Instagram (soon)
Built with Next.js 16 · React 19 · Tailwind 4

Built with Next.js 16 · React 19 · Tailwind 4