0
0
Redisquery~30 mins

Why configuration matters in Redis - See It in Action

Choose your learning style9 modes available
Why Configuration Matters in Redis
📖 Scenario: You are setting up a Redis database for a small online store. Redis will store product stock counts so the store can quickly check availability.
🎯 Goal: Build a simple Redis setup where you create initial stock data, configure a threshold for low stock, check stock levels, and mark products as low stock if needed.
📋 What You'll Learn
Create a Redis hash called product_stock with exact product stock counts
Add a configuration variable low_stock_threshold with value 5
Write a Redis Lua script that checks each product's stock against low_stock_threshold
Add a Redis set low_stock_products to store products below the threshold
💡 Why This Matters
🌍 Real World
Retailers use Redis to quickly check product availability and alert when stock is low to reorder.
💼 Career
Understanding Redis data structures and Lua scripting is valuable for backend developers working on fast, scalable inventory systems.
Progress0 / 4 steps
1
DATA SETUP: Create initial product stock data
Create a Redis hash called product_stock with these exact entries: "apple": "10", "banana": "3", "orange": "7".
Redis
Need a hint?

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

2
CONFIGURATION: Set low stock threshold
Create a Redis string key called low_stock_threshold and set its value to 5.
Redis
Need a hint?

Use the SET command to store a simple configuration value.

3
CORE LOGIC: Check stock levels with Lua script
Write a Redis Lua script that iterates over all products in product_stock, compares each stock count to the low_stock_threshold, and returns a list of products below the threshold. Use redis.call and for loop with variables i and product.
Redis
Need a hint?

Use HKEYS to get all product names, GET to get the threshold, and loop through products to compare stock.

4
COMPLETION: Store low stock products in a Redis set
Use the Lua script to add each product below the threshold into a Redis set called low_stock_products using redis.call('SADD', 'low_stock_products', product) inside the loop.
Redis
Need a hint?

Use SADD inside the loop to add products to the set.