Practice & Assessment
Test your understanding of Redis Fundamentals
Multiple Choice Questions
5What does the TTL command return when a key exists but has no expiry set?
Which Redis data type maintains members in order by a numeric score?
Which persistence mode offers the highest durability at the cost of write throughput?
What is the maximum size of a single String value in Redis?
Which command removes the TTL from a key without deleting it?
Coding Challenges
1Session Store with Expiry
Using redis-cli or any Redis client library, create a function that stores a session token as a Redis String under the key pattern session:<token>, sets a TTL of 30 minutes, and returns the remaining TTL in seconds. Input: a string token and a user ID. Output: the TTL in seconds immediately after setting. Verify with TTL command. Estimated time: 15 minutes.
Mini Project
Redis-Backed User Profile Cache
Build a small Node.js or Python script that reads a user object (id, name, email, age) from a plain JSON file, stores it in Redis as a Hash under user:<id>, sets a 5-minute TTL, and exposes two functions: getUser(id) โ returns the hash from Redis if present, else re-reads from JSON and repopulates; deleteUser(id) โ removes the key. Log whether each getUser call was a cache hit or miss. Use HSET, HGETALL, EXPIRE, and DEL. Demonstrate RDB persistence by stopping and restarting the Redis server and confirming the data survives if saved within the snapshot window.
