Back to results for “JSON”
Redis › Hashes in Redis

How would you decide between storing an object as a single JSON string versus as a native Redis hash, considering both memory usage and access patterns?

Advanced

Answer

You would generally prefer a native hash when your application frequently needs to read or update individual fields independently, since hashes let you avoid retrieving and rewriting the entire object for a small change, while a JSON string might be simpler when you almost always read or write the entire object together and do not need field level access.
-- Hash: efficient for updating a single field
HSET user:100 lastLogin '2026-09-07'

-- JSON string: requires reading, modifying, and rewriting the whole value
SET user:100 '{"name":"Sarah","lastLogin":"2026-09-07"}'
Real-world example A user session system switches from storing session data as a JSON string to a native hash, since it frequently needed to update just the last activity timestamp field without touching the rest of the session data.

Common follow-ups: What are the memory tradeoffs between these two approaches for very large objects?;Does RedisJSON change this decision for applications that need JSON specifically?