Valkey: Storing JSON documents
This documentation is part of the Search and JSON guide. You can view the complete guide here: Store and query JSON documents with the Valkey search module.
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use Valkey cloud solution that delivers numerous advantages, including:
Valkey Adminweb UI included.- Unlimited message size and transfers.
- One-click updates for easy maintenance.
- 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 Valkey cloud hosting solution!
You can store structured documents natively as JSON, without serializing them into strings:
JSON.SET product:1 $ '{"name":"Espresso machine","brand":"Bianca","price":459,"stock":12}'
Reading or updating a single field is fast, atomic, and handled server-side:
JSON.GET product:1 $.price
# "[459]"
JSON.NUMINCRBY product:1 $.stock -1
# "[11]"
This approach eliminates the need to fetch and parse the entire document in your application for every update. For example, decrementing a stock counter is now a single atomic operation. No more race conditions or extra code.
The JSON.* command set matches the API of RedisJSON, so most Valkey and Redis clients work without changes.