0
0
Redisquery~30 mins

Embedding vs referencing in Redis - Hands-On Comparison

Choose your learning style9 modes available
Embedding vs Referencing in Redis
📖 Scenario: You are building a simple Redis database to store information about books and their authors. You want to understand the difference between embedding author details directly inside the book data versus referencing the author data separately.
🎯 Goal: Create Redis data structures to store books and authors using both embedding and referencing methods. Learn how to organize data in Redis for these two approaches.
📋 What You'll Learn
Create a Redis hash for a book with embedded author details
Create a Redis hash for an author separately
Create a Redis hash for a book that references the author by ID
Add a key to link the book to the author ID
💡 Why This Matters
🌍 Real World
Many applications use Redis to store fast-access data like books and authors. Understanding embedding vs referencing helps design efficient data models.
💼 Career
Knowing how to organize data in Redis is useful for backend developers, database administrators, and anyone working with NoSQL databases.
Progress0 / 4 steps
1
Create a Redis hash for a book with embedded author details
Create a Redis hash with the key book:1 that stores the book's title as "Redis Basics" and embed the author's name as "Alice" and birth_year as "1980" inside the same hash.
Redis
Need a hint?

Use the HSET command with the key book:1 and fields title, author_name, and author_birth_year.

2
Create a Redis hash for an author separately
Create a Redis hash with the key author:1 that stores the author's name as "Alice" and birth_year as "1980".
Redis
Need a hint?

Use HSET with key author:1 and fields name and birth_year.

3
Create a Redis hash for a book that references the author by ID
Create a Redis hash with the key book:2 that stores the book's title as "Advanced Redis" and a field author_id with the value "1" to reference the author.
Redis
Need a hint?

Use HSET with key book:2 and fields title and author_id.

4
Add a key to link the book to the author ID
Create a Redis string key book:2:author with the value "author:1" to link the book to the author record.
Redis
Need a hint?

Use the SET command with key book:2:author and value author:1.