Valkey: Storing JSON documents

This documentation is part of the Search and JSON guide. View the full 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 provides a host of benefits, including:

  • Valkey Admin web UI included.
  • Unlimited message size and transfers.
  • Effortless updates with just a click.
  • Optimal performance and robust security powered by a private, dedicated infrastructure.

Save time and simplify your life: 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 removes 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. There are 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.