0
0
Redisquery~15 mins

INCRBY and DECRBY in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Using INCRBY and DECRBY in Redis
📖 Scenario: You are managing a simple online store's inventory using Redis. You need to keep track of the stock count for a product and update it as customers buy or return items.
🎯 Goal: Build a Redis key that stores the stock count for a product and update it using INCRBY and DECRBY commands to increase or decrease the stock.
📋 What You'll Learn
Create a Redis key called product_stock with an initial stock value.
Set a variable for the number of items sold or returned.
Use DECRBY to decrease the stock when items are sold.
Use INCRBY to increase the stock when items are returned.
💡 Why This Matters
🌍 Real World
Managing inventory counts in an online store or warehouse system where stock levels change frequently.
💼 Career
Understanding how to update numeric values efficiently in Redis is important for backend developers and system administrators working with caching and real-time data.
Progress0 / 4 steps
1
Create the initial stock key
Create a Redis key called product_stock and set its value to 100 to represent the initial stock count.
Redis
Need a hint?

Use the SET command to create a key with a number value.

2
Set the number of items sold
Create a variable called items_sold and set it to 3 to represent how many items were sold.
Redis
Need a hint?

Assign the number 3 to the variable items_sold.

3
Decrease stock using DECRBY
Use the DECRBY command on product_stock with the value of items_sold to reduce the stock count.
Redis
Need a hint?

Use DECRBY product_stock 3 to subtract 3 from the stock.

4
Increase stock using INCRBY
Create a variable called items_returned set to 2 and then use the INCRBY command on product_stock with items_returned to add back to the stock.
Redis
Need a hint?

Assign 2 to items_returned and then increase the stock by 2 using INCRBY.