0Pricing
Redis Caching & Messaging (Pub/Sub, Streams) · Lección

Fundamentos de RedisJSON y RedisGraph

Explore el almacenamiento y la consulta de documentos JSON, así como el uso de capacidades de bases de datos de grafos en Redis.

Fundamentos de RedisJSON y RedisGraph es una lección gratuita de Redis Caching & Messaging (Pub/Sub, Streams) en CoddyKit. Esta es la lección 3 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Redis Caching & Messaging (Pub/Sub, Streams), y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Redis Caching & Messaging (Pub/Sub, Streams) incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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!

Preguntas frecuentes

¿La lección «Fundamentos de RedisJSON y RedisGraph» es gratis?

Sí — el texto completo de «Fundamentos de RedisJSON y RedisGraph» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Redis Caching & Messaging (Pub/Sub, Streams), actualiza a CoddyKit PRO. El curso de Redis Caching & Messaging (Pub/Sub, Streams) incluye 4 lecciones en total.

¿Qué aprenderé en «Fundamentos de RedisJSON y RedisGraph»?

Explore el almacenamiento y la consulta de documentos JSON, así como el uso de capacidades de bases de datos de grafos en Redis. Practicas Redis Caching & Messaging (Pub/Sub, Streams) con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Redis Caching & Messaging (Pub/Sub, Streams)?

No se requiere experiencia previa. Redis Caching & Messaging (Pub/Sub, Streams) en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 3 de 4.

¿Cuánto tiempo toma la lección «Fundamentos de RedisJSON y RedisGraph»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Redis Caching & Messaging (Pub/Sub, Streams)?

Sí. Cada lección de Redis Caching & Messaging (Pub/Sub, Streams) incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Descripción general de los módulos de Redis
  2. RediSearch para búsqueda de texto completo
  3. Fundamentos de RedisJSON y RedisGraph
  4. Series temporales con RedisTimeSeries
← Volver a Redis Caching & Messaging (Pub/Sub, Streams)