พื้นฐาน RedisJSON และ RedisGraph
สำรวจการจัดเก็บและค้นหาเอกสาร JSON รวมถึงการใช้ความสามารถของฐานข้อมูลกราฟภายใน Redis
พื้นฐาน RedisJSON และ RedisGraph เป็นบทเรียน Redis Caching & Messaging (Pub/Sub, Streams) ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Redis Caching & Messaging (Pub/Sub, Streams) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Redis Caching & Messaging (Pub/Sub, Streams) มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
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!
คำถามที่พบบ่อย
บทเรียน “พื้นฐาน RedisJSON และ RedisGraph” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “พื้นฐาน RedisJSON และ RedisGraph” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Redis Caching & Messaging (Pub/Sub, Streams) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Redis Caching & Messaging (Pub/Sub, Streams) มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “พื้นฐาน RedisJSON และ RedisGraph”
สำรวจการจัดเก็บและค้นหาเอกสาร JSON รวมถึงการใช้ความสามารถของฐานข้อมูลกราฟภายใน Redis คุณปฏิบัติ Redis Caching & Messaging (Pub/Sub, Streams) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Redis Caching & Messaging (Pub/Sub, Streams) หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Redis Caching & Messaging (Pub/Sub, Streams) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “พื้นฐาน RedisJSON และ RedisGraph” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Redis Caching & Messaging (Pub/Sub, Streams) นี้ได้ไหม
ได้ บทเรียน Redis Caching & Messaging (Pub/Sub, Streams) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- ภาพรวมโมดูลของ Redis
- RediSearch สำหรับการค้นหาข้อความเต็มรูปแบบ
- พื้นฐาน RedisJSON และ RedisGraph
- อนุกรมเวลาด้วย RedisTimeSeries