M4RKYU.SYSEdition 2027
Skip to content
LOCEN/Ontario · CA/▸logs · redisjson enhancing json data handling in redis 3b5hStandbyOK/--:--:--EST
M4M4RK_YUportfolio
  • BuildBuild
    BuildOverview
    • WorkSelected case studies and write-ups
    • GamesPlayable prototypes and game-dev logs
  • GalleryGallery
    GalleryOverview
    • PhotosPhoto collections and visual experiments
    • ShopPrints, posters, and one-off objects
  • WritingWriting
    WritingOverview
    • BlogLong-form devlogs and field notes
    • NotesShort observations, links, snippets
  • ResourcesResources
    ResourcesOverview
    • Tools38 in-browser developer utilities
    • LinksDaily-use dev and design bookmarks
  • AboutAbout
  • ContactContact
中文

syndicated · dev.to / @markyu

RedisJSON Is Useful When You Update Parts of a Document

A practical RedisJSON walkthrough: when to use it, when not to, and the commands that actually matter.

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

On this page

  • Run It Locally
  • Store a Document
  • Update One Field
  • Use NX and XX Intentionally
  • Delete a Field
  • When I Would Use RedisJSON
  • The Practical Rule
  • Command Cheat Sheet

I would not use RedisJSON just because my payload happens to be JSON.

I would use it when I need fast reads and updates against parts of a document without fetching the whole blob, changing it in app code, and writing it back.

Here is the problem.

{
  "id": "user:42",
  "name": "Mark",
  "plan": "free",
  "profile": {
    "city": "Toronto",
    "skills": ["React", "Java", "Redis"]
  },
  "usage": {
    "posts": 23,
    "revisions": 4
  }
}

If this lives as a plain string in Redis, changing usage.revisions means:

  1. GET user:42
  2. Parse JSON in the app
  3. Modify one field
  4. SET user:42 ...

That is boring code, and boring code becomes dangerous when two requests update different fields at the same time.

RedisJSON gives you path-level commands instead.

Run It Locally

Use Redis Stack if you want the quickest local setup:

docker run --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest

Then connect:

redis-cli

Store a Document

JSON.SET user:42 $ '{
  "id": "user:42",
  "name": "Mark",
  "plan": "free",
  "profile": {
    "city": "Toronto",
    "skills": ["React", "Java", "Redis"]
  },
  "usage": {
    "posts": 23,
    "revisions": 4
  }
}'

Read the whole thing:

JSON.GET user:42

Read one field:

JSON.GET user:42 $.profile.city

That is the first real win. You can ask for the part you need.

Update One Field

Upgrade the user:

JSON.SET user:42 $.plan '"pro"'

Increment a counter:

JSON.NUMINCRBY user:42 $.usage.revisions 1

Append a skill:

JSON.ARRAPPEND user:42 $.profile.skills '"Three.js"'

Read it back:

JSON.GET user:42 $.plan $.usage $.profile.skills

This is where RedisJSON feels better than manual serialization. Your command says exactly what changed.

Use NX and XX Intentionally

When adding fields, be explicit.

Only set profile.website if it does not exist:

JSON.SET user:42 $.profile.website '"https://www.m4rkyu.com"' NX

Only update plan if it already exists:

JSON.SET user:42 $.plan '"team"' XX

I like this because it turns "oops, I accidentally created the wrong shape" into a failed command instead of silent data drift.

Delete a Field

JSON.DEL user:42 $.profile.website

Delete the whole document with regular Redis:

DEL user:42

When I Would Use RedisJSON

Good fits:

  • Session-like documents that change small fields often.
  • Feature flags or user settings with nested structure.
  • Product/catalog snapshots that need fast reads.
  • Cached API responses where you update selected paths.

Weak fits:

  • Long-term source-of-truth data with complex relational queries.
  • Analytics workloads.
  • Huge documents that grow without discipline.
  • Anything you need to join across many entities.

RedisJSON is not a relational database replacement. It is a sharp Redis tool for JSON-shaped data.

The Practical Rule

If your app always reads and writes the entire object, plain Redis strings are probably enough.

If your app frequently changes nested fields, increments values, appends to arrays, or reads selected paths, RedisJSON earns its place.

Command Cheat Sheet

JSON.SET user:42 $ '{"name":"Mark"}'
JSON.GET user:42 $
JSON.GET user:42 $.name
JSON.SET user:42 $.plan '"pro"'
JSON.NUMINCRBY user:42 $.usage.revisions 1
JSON.ARRAPPEND user:42 $.profile.skills '"Redis"'
JSON.DEL user:42 $.profile.website
JSON.TYPE user:42 $.profile.skills

That is enough to start. Add search/indexing later only when you have a real query that needs it.

Related reading

Bad Data Quality Costs More Than a Slow Query

A practical data quality guide for engineers: validation, ownership, schema drift, observability, and fixing bad data before dashboards lie.

data

Database Table Design Starts With the Queries You Need

A practical database table design guide focused on queries, keys, indexes, normalization, constraints, and production tradeoffs.

database

Debug a Slow MySQL Query Before You Guess at Indexes

A practical MySQL workflow for finding slow queries, reading EXPLAIN output, and deciding whether an index actually helps.

mysql

originally published

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

Continue on dev.to
PreviousDatabase Table Design Starts With the Queries You NeedA practical database table design guide focused on queries, keys, indexes, normalization, constraints, and production tradeoffs.
Back to all posts
NextJava BeanUtils Copying: Convenient, but Not FreeA practical Java guide to BeanUtils, shallow copy pitfalls, reflection overhead, and when MapStruct or manual mapping is a better choice.
Back to archive
M4RKYUM4RKYUM4RKYUM4RKYUM4RKYUM4RKYUM4RKYUM4RKYU
Crafted since 2024
ZhenXiao Mark YuZhenXiao Mark Yu
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
open channel

say hi anytime · 2026

--:--:--ESTOntario, Canada
  • Email
  • GitHub
  • dev.to
  • LinkedIn
  • Twitter / X
  • Instagram
  • Facebook
  • YouTube
  • CodePen
  • Spotify
  • Snapchat

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
  • Shop
RSSJSON feed

Studio

Background, contact, and channels for collaboration.

  • About
  • Contact
  • Changelog
  • Colophon
  • Resumepending

Socials

Find me on the usual feeds.

  • GitHub
  • dev.to
  • LinkedIn
  • Twitter / X
  • Instagram
  • Facebook
  • YouTube
  • CodePen
  • Spotify
  • Snapchat
  • Email
© 2026 ZhenXiao Mark Yumarkyu0615@gmail.com
  • Email
  • GitHub
  • dev.to
  • LinkedIn
  • Twitter / X
  • Instagram
  • Facebook
  • YouTube
  • CodePen
  • Spotify
  • Snapchat
PrivacyTermsBuilt with Next.js 16 · React 19 · Tailwind 4