Redis®*: Storing JSON documents
This documentation is part of the Search and JSON guide. You can view the complete guide here: Store JSON documents and query them efficiently with the Redis query engine.
👋 Welcome to the Stackhero documentation!
Stackhero provides a ready-to-use Redis cloud solution offering numerous advantages, including:
- Redis Commander web interface included.
- Unlimited message size and transfers.
- Updates made easy with just one click.
- Optimal performance and enhanced security thanks to a private, dedicated infrastructure.
Save time and make your life easier: it only takes 5 minutes to try Stackhero's Redis cloud hosting solution!
Instead of serialising your documents as strings, you can store them natively in JSON format:
JSON.SET product:1 $ '{"name":"Espresso machine","brand":"Bianca","price":459,"tags":["coffee","kitchen"],"stock":12}'
This method allows you to read or update individual fields atomically and server-side:
JSON.GET product:1 $.price
# "[459]"
JSON.NUMINCRBY product:1 $.stock -1
# "[11]"
JSON.ARRAPPEND product:1 $.tags '"gift"'
This approach simplifies your workflows and reduces errors. For example, decrementing a stock counter does not require reading, parsing, and rewriting the entire document in your application. The operation is performed instantly and safely on the server side.
You can find the full list of commands in the Redis JSON documentation.