Redis®*: Storing JSON documents

This documentation is part of the Search and JSON guide. View the full guide here: Store JSON documents and query them efficiently with the Redis query engine.

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use Redis cloud solution that provides a host of benefits, including:

  • Redis Commander 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 Redis cloud hosting solution!

You can store documents natively as JSON, instead of serializing them as strings:

JSON.SET product:1 $ '{"name":"Espresso machine","brand":"Bianca","price":459,"tags":["coffee","kitchen"],"stock":12}'

This approach lets you 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 workflow saves effort and reduces errors. For example, decrementing a stock counter does not require reading, parsing, and rewriting the entire document in your application. Instead, it happens safely and immediately on the server.

You can find the full list of commands in the Redis JSON documentation.