Redis Beginner Quiz
30 questions on Redis Basics.
Question 1: What does Redis stand for?
- A. Relational Database Interface System
- B. Remote Dictionary Server β (correct answer)
- C. Rapid Data Storage
- D. Runtime Data Structure
Explanation: Redis is an open-source, in-memory data structure store, used as a database, cache, and message broker.
Question 2: What type of database is Redis primarily classified as?
- A. Relational Database
- B. Document Database
- C. Graph Database
- D. In-Memory Key-Value Store β (correct answer)
Explanation: Redis stores data as simple key-value pairs directly in the server's RAM, making it incredibly fast.
Question 3: Why is Redis so much faster than traditional databases like MySQL or PostgreSQL?
- A. It uses a faster query language
- B. It ignores security protocols
- C. It stores all data in the system's primary memory (RAM) instead of on a hard drive (Disk) β (correct answer)
- D. It only stores numbers
Explanation: Accessing RAM is orders of magnitude faster than reading from SSDs or HDDs, allowing Redis to perform millions of operations per second.
Question 4: Which command is used to store a string value in Redis?
- A.
PUT
- B.
INSERT
- C.
SET β (correct answer)
- D.
ADD
Explanation: SET key "value" is the fundamental command to store a string in Redis.
Question 5: Which command is used to retrieve a string value in Redis?
- A.
GET β (correct answer)
- B.
FETCH
- C.
SELECT
- D.
PULL
Explanation: GET key returns the value associated with that key. If the key doesn't exist, it returns nil.
Question 6: How do you set a key to automatically delete itself after a certain number of seconds?
- A.
SET_TIMEOUT
- B.
EXPIRE β (correct answer)
- C.
DELETE_AFTER
- D.
KILL
Explanation: EXPIRE mykey 60 tells Redis to automatically delete mykey after 60 seconds. This is crucial for caching.
Question 7: What does the TTL command do?
- A. Total Time Logged
- B. Returns the remaining Time To Live of a key that has an expiration set β (correct answer)
- C. Translates Text Language
- D. Terminates The Local server
Explanation: TTL mykey returns the number of seconds remaining before the key is automatically deleted.
Question 8: Which command is used to delete a key manually?
- A.
DROP
- B.
REMOVE
- C.
DEL β (correct answer)
- D.
ERASE
Explanation: DEL mykey immediately removes the key and its associated value from memory.
Question 9: What does the INCR command do?
- A. Increments the size of the database
- B. Increments the integer value of a key by 1 β (correct answer)
- C. Increases the server RAM
- D. Increments the expiration timer
Explanation: INCR views is an atomic operation that instantly adds 1 to the current value of the "views" key. It is perfect for view counters or rate limiters.
Question 10: What is a Redis "List"?
- A. A collection of unique strings
- B. A collection of string elements sorted according to the order of insertion (essentially a Linked List) β (correct answer)
- C. An array of integers only
- D. A relational table
Explanation: Lists allow you to push and pop elements from both the head (Left) and the tail (Right) extremely quickly.
Question 11: Which command adds an element to the LEFT (head) of a List?
- A.
ADDL
- B.
LADD
- C.
LPUSH β (correct answer)
- D.
LINSERT
Explanation: LPUSH mylist "apple" pushes "apple" to the front of the list.
Question 12: Which command removes and returns the element from the RIGHT (tail) of a List?
- A.
RPOP β (correct answer)
- B.
POP_RIGHT
- C.
REMOVE_R
- D.
RGET
Explanation: RPOP mylist pops the last element off the list. Using LPUSH and RPOP together creates a perfect Queue (FIFO).
Question 13: What is a Redis "Set"?
- A. An ordered collection of strings
- B. An unordered collection of unique strings β (correct answer)
- C. A set of configuration rules
- D. A set of database backups
Explanation: Sets (SADD, SMEMBERS) do not allow duplicate values. If you add "apple" twice, it only appears once.
Question 14: What is a Redis "Hash"?
- A. An encrypted password
- B. A map between string fields and string values, perfect for representing objects (like a User) β (correct answer)
- C. A broken data block
- D. A fast search algorithm
Explanation: Hashes (HSET user:1 name "John" age "30") act like dictionaries or JSON objects, allowing you to access individual fields without loading the whole object.
Question 15: What does the HGETALL command do?
- A. Gets all keys in the database
- B. Gets all fields and values of a Hash β (correct answer)
- C. Gets all Hashes in the database
- D. Gets all historical commands
Explanation: HGETALL user:1 returns the complete object (e.g., name, John, age, 30).
Question 16: What is a "Sorted Set" (ZSET) in Redis?
- A. A set sorted alphabetically
- B. A collection of unique strings where every string is associated with a floating-point number called a "score", allowing sorting by that score β (correct answer)
- C. A set that automatically sorts by insertion time
- D. A normal set that has been indexed
Explanation: Sorted Sets (ZADD leaderboard 100 "Player1") are the ultimate tool for creating real-time leaderboards.
Question 17: What does the EXISTS command do?
- A. Checks if the Redis server is running
- B. Returns 1 if a key exists, and 0 if it does not β (correct answer)
- C. Checks if a user exists in the SQL database
- D. Prevents a key from expiring
Explanation: EXISTS mykey is a fast boolean check to see if a key is currently stored in memory.
Question 18: What is Redis Pub/Sub?
- A. A publishing company
- B. A messaging paradigm where senders (Publishers) send messages to channels, and receivers (Subscribers) listen to those channels β (correct answer)
- C. A backup mechanism
- D. A type of sorted list
Explanation: Pub/Sub is used for real-time chat apps, notifications, and microservice communication.
Question 19: Which command is used to publish a message to a channel?
- A.
SEND
- B.
EMIT
- C.
PUBLISH β (correct answer)
- D.
BROADCAST
Explanation: PUBLISH news "Hello World" sends the string "Hello World" to anyone currently subscribed to the "news" channel.
Question 20: If Redis stores everything in RAM, what happens when the server restarts or crashes?
- A. All data is permanently lost forever with no recovery options
- B. Redis can recover data using persistence mechanisms like RDB snapshots or AOF (Append Only File) logs written to disk β (correct answer)
- C. It downloads the data from the internet
- D. It stores it in the CPU cache
Explanation: While primarily in-memory, Redis periodically saves data to the hard drive so it can be restored on boot.
Question 21: What does FLUSHALL do?
- A. Clears the server cache
- B. Deletes all keys from all databases on the Redis server β (correct answer)
- C. Resets the network connection
- D. Reboots the server
Explanation: FLUSHALL completely wipes the entire Redis instance. Use with extreme caution!
Question 22: What does the KEYS * command do, and why should you avoid it in production?
- A. It generates a master password; it's a security risk
- B. It returns every single key in the database; it blocks the single-threaded server and causes massive lag on large datasets β (correct answer)
- C. It unlocks all records; it removes encryption
- D. It formats the database
Explanation: Redis is single-threaded. If it spends 5 seconds fetching 10 million keys, every other command in the application is paused for those 5 seconds. Use SCAN instead.
Question 23: What is the SCAN command used for?
- A. Scanning the server for viruses
- B. Safely iterating over a large collection of keys in small batches without blocking the server β (correct answer)
- C. Converting strings to integers
- D. Scanning barcodes
Explanation: SCAN returns a small array of keys and a cursor to fetch the next batch, keeping the server responsive.
Question 24: What is a "Redis Transaction"?
- A. Buying a Redis license
- B. A block of commands executed sequentially as a single isolated operation using
MULTI and EXEC β (correct answer)
- C. Moving data between servers
- D. A SQL query
Explanation: MULTI starts the transaction queue, and EXEC executes all queued commands atomically.
Question 25: What is the most common use case for Redis in a web application?
- A. Storing large video files
- B. Acting as the primary, long-term relational database
- C. Caching frequently accessed data (like database query results or session data) to reduce load on the primary database β (correct answer)
- D. Writing CSS
Explanation: Because it is in-memory, serving data from Redis takes microseconds, vastly improving website speed.
Question 26: What does an "Eviction Policy" like allkeys-lru do when Redis runs out of RAM?
- A. It crashes the server
- B. It deletes the Least Recently Used (LRU) keys to make room for new data β (correct answer)
- C. It randomly deletes keys
- D. It stops accepting new writes and returns an error
Explanation: LRU ensures that stale cache data is automatically purged, while actively used data remains in memory.
Question 27: What does the PING command do?
- A. Checks the internet speed
- B. Tests if the Redis server is responsive (it replies with "PONG") β (correct answer)
- C. Connects to a SQL database
- D. Drops the database
Explanation: PING is the standard way to test if your application successfully connected to the Redis instance.
Question 28: What does SETNX stand for?
- A. Set Next
- B. Set if Not eXists β (correct answer)
- C. Set No Expiration
- D. Set Negative X
Explanation: SETNX only sets the key if it doesn't already exist. It is commonly used to create distributed locks across multiple servers.
Question 29: In a Redis Hash, which command gets the value of a single specific field?
- A.
GET
- B.
HGET β (correct answer)
- C.
FETCH_HASH
- D.
HSELECT
Explanation: HGET user:1 name will return just the name field from the hash, without loading the rest of the object.
Question 30: What is the default port number that Redis listens on?
- A. 80
- B. 3306
- C. 5432
- D. 6379 β (correct answer)
Explanation: Redis uses port 6379 (which corresponds to "MERZ" on a phone keypad, named after an Italian showgirl by the creator).