Script Valley
Redis: Complete Course
Transactions, Scripting, and Pipelines/Assessment

Practice & Assessment

Test your understanding of Transactions, Scripting, and Pipelines

Multiple Choice Questions

5
1

After EXEC returns nil in a WATCH transaction, what should your code do?

2

What is the key difference between a pipeline and a MULTI/EXEC transaction?

3

Which Redis feature replaces WATCH+MULTI/EXEC for complex conditional operations under high contention?

4

In a fixed-window rate limiter using INCR, why must you set the TTL on the first request only?

5

What does SCRIPT LOAD return, and how is it used?

Coding Challenges

1
1

Atomic Inventory Decrement

Implement a purchaseItem(itemId, quantity) function using a Lua script that: reads the current inventory count for inventory:<itemId>, checks that inventory >= quantity, decrements by quantity if sufficient, and returns {success: true, remaining: N} or {success: false, reason: 'out-of-stock'}. The entire check-and-decrement must be atomic. Seed inventory:<sword> with 10. Call purchaseItem 12 times and log each result. Input: string itemId, integer quantity. Output: result object. Estimated time: 20 minutes.

Medium

Mini Project

1

Redis-Powered Rate Limiter Middleware

Build an Express.js middleware that rate-limits API requests per IP address. Implement three strategies and expose each on a different route: /api/fixed — fixed window, 10 requests per 10 seconds using INCR+EXPIRE; /api/sliding — sliding window, 10 requests per 10 seconds using Sorted Set with ZREMRANGEBYSCORE and ZADD; /api/token — token bucket, replenishes 1 token per second, max 10 tokens using Lua script for atomic check-and-decrement. Return 429 with a Retry-After header when the limit is exceeded. Return X-RateLimit-Remaining and X-RateLimit-Reset headers on every response. Include a test script that fires 25 concurrent requests to each route and logs the responses.

Hard