Grundlagen von RedisJSON und RedisGraph
Erkunden Sie das Speichern und Abfragen von JSON-Dokumenten sowie die Nutzung von Graphdatenbankfunktionen in Redis.
Grundlagen von RedisJSON und RedisGraph ist eine kostenlose Redis Caching & Messaging (Pub/Sub, Streams)-Lektion auf CoddyKit. Dies ist Lektion 3 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Redis Caching & Messaging (Pub/Sub, Streams)-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Redis Caching & Messaging (Pub/Sub, Streams)-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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 $.nameUpdating 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:1Introducing 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!
Häufig gestellte Fragen
Ist die Lektion „Grundlagen von RedisJSON und RedisGraph“ kostenlos?
Ja — der vollständige Text von „Grundlagen von RedisJSON und RedisGraph“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Redis Caching & Messaging (Pub/Sub, Streams)-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Redis Caching & Messaging (Pub/Sub, Streams)-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Grundlagen von RedisJSON und RedisGraph“?
Erkunden Sie das Speichern und Abfragen von JSON-Dokumenten sowie die Nutzung von Graphdatenbankfunktionen in Redis. Du übst Redis Caching & Messaging (Pub/Sub, Streams) mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Redis Caching & Messaging (Pub/Sub, Streams) zu starten?
Keine Vorkenntnisse erforderlich. Redis Caching & Messaging (Pub/Sub, Streams) auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 3 von 4.
Wie lange dauert die Lektion „Grundlagen von RedisJSON und RedisGraph“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Redis Caching & Messaging (Pub/Sub, Streams)-Lektion Code schreiben und ausführen?
Ja. Jede Redis Caching & Messaging (Pub/Sub, Streams)-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Überblick über Redis Modules
- RediSearch für die Volltextsuche
- Grundlagen von RedisJSON und RedisGraph
- Zeitreihen mit RedisTimeSeries