0
0
Redisquery~30 mins

Write-through pattern in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Implementing Write-Through Pattern with Redis
📖 Scenario: You are building a simple caching system for a product catalog using Redis. The goal is to keep the cache and the database synchronized so that when a product's price is updated, both the cache and the database reflect the change immediately.
🎯 Goal: Build a write-through cache pattern where updates to product prices are written to both Redis cache and the database at the same time.
📋 What You'll Learn
Create a Redis hash to store product prices with exact keys and values
Define a variable for the database simulation with the same product data
Write a function to update the product price in both Redis and the database
Ensure the final code updates both data stores correctly
💡 Why This Matters
🌍 Real World
Write-through caching is used in web applications to keep cache and database synchronized, improving performance and data consistency.
💼 Career
Understanding write-through patterns is important for backend developers and database administrators working with caching systems and data synchronization.
Progress0 / 4 steps
1
Create Redis hash with product prices
Create a Redis hash called product_prices with these exact entries: product1: 100, product2: 200, product3: 300.
Redis
Need a hint?

Use the HMSET command to create a hash with multiple fields and values.

2
Simulate database with a dictionary
Create a variable called database as a dictionary with these exact entries: 'product1': 100, 'product2': 200, 'product3': 300.
Redis
Need a hint?

Use Python dictionary syntax to create the database variable.

3
Write update function for write-through
Write a function called update_price that takes product and new_price as parameters and updates the price in both the Redis hash product_prices and the database dictionary.
Redis
Need a hint?

Use the HSET command to update Redis and assign the new price in the dictionary.

4
Complete write-through update with Redis command execution
Add a line inside update_price to execute the Redis command string stored in redis_command using a Redis client method called execute_command.
Redis
Need a hint?

Call redis_client.execute_command(redis_command) to send the update to Redis.