0Pricing
Redis Caching & Messaging (Pub/Sub, Streams) · Lesson

RedisJSON & RedisGraph Basics

Explore storing and querying JSON documents and leveraging graph database capabilities within Redis.

RedisJSON & RedisGraph Basics is a free Redis Caching & Messaging (Pub/Sub, Streams) lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Redis Caching & Messaging (Pub/Sub, Streams) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Unlock New Data Types

Redis is incredibly versatile, but sometimes you need more specialized data handling. That's where Redis Modules come in!

These modules extend Redis's core functionality, allowing it to act as a document database, a graph database, and much more.

Introducing RedisJSON

RedisJSON is a module that lets you store, update, and retrieve JSON documents directly within Redis. This is great for managing semi-structured data like user profiles, product catalogs, or configuration settings.

  • Native JSON support: Store complex JSON objects.
  • Atomic operations: Update parts of a JSON document efficiently.
  • Powerful querying: Retrieve data using JSONPath expressions.

Storing JSON with JSON.SET

To store a JSON document, we use the JSON.SET command. You provide a key, a path (usually $ for the root), and the JSON string.

Try adding a simple user profile:

JSON.SET user:profile:1 $ '{"name": "Emma", "age": 28, "city": "London"}'

Retrieving JSON with JSON.GET

The JSON.GET command retrieves your JSON. You can get the entire document or specify a JSONPath to fetch only specific fields.

Let's get the full profile and then just Emma's name:

JSON.GET user:profile:1
JSON.GET user:profile:1 $.name

Updating JSON Fields

One of RedisJSON's strengths is updating specific parts of a document without fetching and rewriting the whole thing. Use JSON.SET with a precise path.

Update Emma's age and add a new hobby:

JSON.SET user:profile:1 $.age 29
JSON.SET user:profile:1 $.hobbies '["reading", "hiking"]'
JSON.GET user:profile:1

Introducing RedisGraph

RedisGraph is another powerful module that turns Redis into a graph database. Graph databases are excellent for modeling relationships between data, like social networks, recommendation engines, or fraud detection.

Instead of tables, you work with nodes (entities) and edges (relationships).

Graph Concepts

In RedisGraph, you'll use Cypher, a declarative graph query language, to interact with your data.

  • Nodes: Represent entities (e.g., Person, Product).
  • Labels: Categorize nodes (e.g., :Person).
  • Properties: Attributes of nodes/edges (e.g., name: 'Bob').
  • Edges: Represent relationships (e.g., -[:FRIENDS_WITH]->).

Creating Graph Data

The GRAPH.QUERY command lets you execute Cypher queries. Let's create a simple social graph with two people and a 'FRIENDS_WITH' relationship.

Notice the graph name 'social' is used to identify our graph.

GRAPH.QUERY social "CREATE (:Person {name: 'Liam'})-[:FRIENDS_WITH]->(:Person {name: 'Olivia'})"

Querying Graph Relationships

You can query the graph to find patterns and relationships. The MATCH clause finds the pattern, and RETURN specifies what data to retrieve.

Find who Liam is friends with:

GRAPH.QUERY social "MATCH (p:Person {name: 'Liam'})-[:FRIENDS_WITH]->(f:Person) RETURN p.name, f.name"

RedisJSON Path Challenge

You have a RedisJSON document stored under the key product:details:123. The document looks like this:

{
  "name": "Wireless Earbuds",
  "specs": {
    "color": "Black",
    "battery_life": "8 hours",
    "features": ["Noise Cancelling", "Waterproof"]
  }
}

Which command correctly retrieves the 'Noise Cancelling' feature?

Recap: JSON & Graphs

You've explored how RedisJSON enables efficient storage and manipulation of JSON documents using commands like JSON.SET and JSON.GET with JSONPath.

You also learned about RedisGraph, a powerful module for building and querying graph structures using Cypher, perfect for modeling relationships between data.

These modules significantly expand Redis's capabilities, letting it tackle a broader range of data modeling challenges!

Frequently asked questions

Is the “RedisJSON & RedisGraph Basics” lesson free?

Yes — the full text of “RedisJSON & RedisGraph Basics” is free to read here on the web, and the Redis Caching & Messaging (Pub/Sub, Streams) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Redis Caching & Messaging (Pub/Sub, Streams) course, upgrade to CoddyKit PRO.

What will I learn in “RedisJSON & RedisGraph Basics”?

Explore storing and querying JSON documents and leveraging graph database capabilities within Redis. You practise Redis Caching & Messaging (Pub/Sub, Streams) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Redis Caching & Messaging (Pub/Sub, Streams)?

No prior experience is required. Redis Caching & Messaging (Pub/Sub, Streams) on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “RedisJSON & RedisGraph Basics” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Redis Caching & Messaging (Pub/Sub, Streams) lesson?

Yes. Every Redis Caching & Messaging (Pub/Sub, Streams) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Overview of Redis Modules
  2. RediSearch for Full-Text Search
  3. RedisJSON & RedisGraph Basics
  4. Time Series with RedisTimeSeries
← Back to Redis Caching & Messaging (Pub/Sub, Streams)