0
0
Redisquery~30 mins

Multi-key transactions for consistency in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Multi-key Transactions for Consistency in Redis
📖 Scenario: You are managing a simple bank system where users have accounts with balances stored in Redis. You want to ensure that when transferring money from one user to another, the balances update correctly and consistently, even if multiple transfers happen at the same time.
🎯 Goal: Build a Redis transaction that safely transfers money between two user accounts by updating both balances atomically.
📋 What You'll Learn
Create two keys representing user balances with exact names and values
Set a transfer amount variable
Use Redis MULTI/EXEC commands to perform the transfer atomically
Ensure the transaction updates both user balances correctly
💡 Why This Matters
🌍 Real World
Banking and financial applications require consistent updates to multiple related data points, like account balances, to avoid errors and data corruption.
💼 Career
Understanding Redis transactions is essential for backend developers working with real-time data stores to maintain data integrity during concurrent operations.
Progress0 / 4 steps
1
DATA SETUP: Create user balance keys
Create two Redis keys called user:Alice:balance and user:Bob:balance with values 1000 and 500 respectively using the SET command.
Redis
Need a hint?

Use the SET command to assign the initial balances.

2
CONFIGURATION: Define the transfer amount
Create a Redis key called transfer:amount and set its value to 200 using the SET command.
Redis
Need a hint?

Use SET transfer:amount 200 to define the amount to transfer.

3
CORE LOGIC: Start a transaction to transfer money
Start a Redis transaction with MULTI. Then use DECRBY user:Alice:balance 200 and INCRBY user:Bob:balance 200 to subtract and add the transfer amount. Do not execute the transaction yet.
Redis
Need a hint?

Use MULTI to start the transaction, then queue the decrement and increment commands.

4
COMPLETION: Execute the transaction
Complete the Redis transaction by adding the EXEC command to execute all queued commands atomically.
Redis
Need a hint?

Use EXEC to run the transaction and apply all changes atomically.