Intermediate Redis test (Intermediate)
30 questions · 35 minutes · Free
Caching patterns, sorted sets, pub/sub, transactions and persistence.
Take the Intermediate Redis test
What it covers
- Caching patterns with Redis
- Redis sorted sets
- Redis pub/sub
- Redis transactions
- Redis RDB and AOF persistence
Interview format
- Questions: 30 questions — 18 multiple choice, 9 multi-answer, 3 predict-the-output
- Time: 35 minutes, timed from the first question
- Difficulty: Intermediate
- Skill area: Data
- Price: Free
Earn a certificate
The Intermediate Redis test is one of the 8 tests of the Backend Developer learning path. Pass it and the other 7 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.
Sample questions
5 sample questions from the Intermediate Redis test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.
Which of the following accurately describes how RDB snapshots behave in Redis?
- RDB snapshots store every single write operation, which makes them ideal for data recovery.
- RDB snapshots use a log-based approach, similar to AOF, to ensure data persistence.
- RDB snapshots are stored as plain text files, making them human-readable and easy to debug.
- RDB snapshots are point-in-time snapshots of the dataset and are compact, making them efficient for fast restarts.
Answer: D. RDB snapshots are point-in-time snapshots of the dataset and are compact, making them efficient for fast restarts.
RDB snapshots are created by Redis using a binary format that is compact and efficient. They capture the state of the dataset at a specific point in time, which allows for quick restarts of the Redis server. This is different from AOF, which logs all write operations and is not as compact. RDB snapshots are generated using commands like `SAVE` or `BGSAVE`, and they do not store every write operation, but rather a snapshot of the data at a particular moment.
You are implementing a leaderboard in Redis and need to retrieve all users in ascending order of their scores along with their scores. Which Redis command would you use?
- ZRANGE leaderboard 0 -1 WITHSCORES
- ZCOUNT leaderboard 0 1000
- ZRANGEBYSCORE leaderboard 0 1000 WITHSCORES
- ZREVRANGE leaderboard 0 -1 WITHSCORES
Answer: A. ZRANGE leaderboard 0 -1 WITHSCORES
The `ZRANGE` command with `WITHSCORES` is used to retrieve all members of a sorted set in ascending order along with their scores. This is the correct approach for retrieving all members of a leaderboard in a sorted manner. `ZREVRANGE` would return the members in descending order, `ZRANGEBYSCORE` is used for range-based queries, and `ZCOUNT` only returns the count of members in a score range, not the members themselves.
Which Redis command is the most efficient way to retrieve all members in a sorted set with scores between 100 and 200?
- Use `ZRANGE` with an index-based approach.
- Use `ZRANGEBYSCORE` with a minimum and maximum score range.
- Use `ZCOUNT` to retrieve members within a score range.
- Use `ZSCAN` to iterate through the sorted set.
Answer: B. Use `ZRANGEBYSCORE` with a minimum and maximum score range.
To efficiently retrieve all members in a Redis sorted set with scores between 100 and 200, the correct approach is to use the `ZRANGEBYSCORE` command with the specified score range. This command is optimized for range queries and returns members in the specified score interval. Using `ZRANGE` with an index-based approach is not efficient for score-based queries, and `ZSCAN` is not a Redis command for sorted sets. `ZCOUNT` only returns the count of members within a score range and does not retrieve the actual members.
What does the `PUBLISH` command in Redis return when a message is sent to a channel?
- It returns an error if no subscribers are connected.
- It returns the message content as a string.
- It returns the channel name and message together.
- It returns the number of subscribers that received the message.
Answer: D. It returns the number of subscribers that received the message.
The `PUBLISH` command in Redis sends a message to all subscribers of a channel and returns the number of subscribers that received the message. This is a fundamental aspect of Redis pub/sub, where messages are delivered to connected subscribers, and the return value indicates how many subscribers received the message.
What data type can be used as a score in a Redis sorted set?
- A complex number
- A float (including integers)
- A string
- A binary data type
Answer: B. A float (including integers)
In Redis sorted sets, the score is stored as a float, which allows for both integer and decimal values. This is a key detail, as it enables precise ordering and ranking operations. Other options are incorrect because Redis does not support strings, binary data, or complex numbers as scores in sorted sets.
Frequently asked questions
- How many questions are in the Intermediate Redis test?
- 30 questions (18 multiple choice, 9 multi-answer, 3 predict-the-output), with 35 minutes to answer them.
- What does the Intermediate Redis test cover?
- Caching patterns with Redis, Redis sorted sets, Redis pub/sub, Redis transactions, Redis RDB and AOF persistence.
- Is the Intermediate Redis test free?
- Yes. It is free to take with a readyforhires account.
- What level is the Intermediate Redis test?
- Intermediate, in Data.