




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This exam provides training on Redis database development. Participants will learn data structures, key management, caching strategies, performance optimization, and integration with applications. Labs simulate real-world enterprise use cases for hands-on learning.
Typology: Exams
1 / 118
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1 Which persistence mode creates point‑in‑time snapshots of the dataset at specified intervals? A) AOF B) RDB C) Replication D) Lazyfree Answer: B Explanation: RDB (Redis Database) persistence takes snapshots of the dataset at configured times, producing a compact binary file. Question 2 What is the time complexity of the Redis command LPUSH? A) O(1) B) O(log N) C) O(N) D) O(N log N) Answer: A Explanation: LPUSH inserts an element at the head of a list in constant time regardless of list length. Question 3
Which configuration directive controls the maximum amount of memory Redis may allocate? A) maxclients B) maxmemory C) timeout D) save Answer: B Explanation: maxmemory sets the upper limit for memory usage; once reached, Redis applies the chosen eviction policy. Question 4 In the Redis Serialization Protocol (RESP), which prefix denotes an array? A) + B) : C) $ D) * Answer: D Explanation: The asterisk (*) indicates the start of an array in RESP, followed by the number of elements. Question 5 Which command should be avoided in production for scanning keys because it blocks the server?
Answer: C Explanation: The NX flag tells Redis to set the key only when it is absent. Question 8 How can you atomically increment a numeric string value by 5? A) INCRBY key 5 B) INCR key 5 C) SET key + D) APPEND key 5 Answer: A Explanation: INCRBY adds the specified integer to the current value in a single atomic operation. Question 9 Which data structure is best suited for implementing a real‑time leaderboard? A) List B) Set C) Sorted Set (ZSET) D) Hash
Answer: C Explanation: Sorted Sets maintain elements ordered by a score, enabling fast rank queries for leaderboards. Question 10 What is the time complexity of ZRANGE when retrieving a range of elements? A) O(1) B) O(log N) C) O(M + log N) where M is the number of returned elements D) O(N) Answer: C Explanation: ZRANGE is logarithmic to locate the start, then linear in the number of elements returned. Question 11 Which command returns the remaining time to live of a key in milliseconds? A) TTL B) PTTL C) EXPIRETIME D) TIMELEFT Answer: B Explanation: PTTL reports the TTL in milliseconds, while TTL reports seconds.
Which command removes and returns a random element from a set? A) SPOP B) SRANDMEMBER C) SREM D) SMEMBERS Answer: A Explanation: SPOP removes a random member from the set and returns it. Question 15 When using ZADD with the NX flag, what happens if the member already exists? A) Its score is updated B) The command is ignored C) An error is returned D) A new member is added with a duplicate name Answer: B Explanation: NX means “only add if not exists”; existing members are left unchanged. Question 16 Which command is used to persist the in‑memory dataset to disk without waiting for the scheduled snapshot?
Answer: A Explanation: SAVE performs a synchronous snapshot, blocking the server until the RDB file is written. Question 17 What is the default eviction policy when maxmemory is reached and no policy is set? A) noeviction B) allkeys-lru C) volatile-lru D) volatile-random Answer: A Explanation: noeviction rejects write commands when memory limit is reached, preserving all data. Question 18 Which command retrieves all fields and values of a hash in a single call? A) HGETALL
Answer: B Explanation: SCAN is a cursor‑based iterator that may return the same key multiple times; callers must deduplicate. Question 21 Which data type is most appropriate for storing a user's profile with fields like name, email, and age? A) List B) Set C) Hash D) Sorted Set Answer: C Explanation: Hashes map field names to values, ideal for representing objects with multiple attributes. Question 22 What is the effect of the RENAMENX command if the new key already exists? A) Overwrites the existing key B) Fails and returns 0 C) Deletes the existing key and renames D) Renames and returns an error Answer: B
Explanation: RENAMENX only renames when the destination key does not exist; otherwise it returns 0. Question 23 Which command can be used to atomically set a key with a value only if the key already exists? A) SET NX B) SET XX C) SETEX D) SETBIT Answer: B Explanation: The XX flag for SET updates the key only when it already exists. Question 24 In Redis Cluster, what determines the node that stores a given key? A) The key’s length B) The first character of the key C) A 16384‑slot hash of the key D) Random assignment at runtime Answer: C Explanation: Redis Cluster uses CRC16 to map keys to one of 16384 hash slots; each slot is assigned to a node.
Question 27 Which command returns the number of elements in a Redis list? A) LLEN B) LSIZE C) LISTLEN D) LCOUNT Answer: A Explanation: LLEN reports the length of a list in constant time. Question 28 What does the BRPOP command do? A) Pops an element from the left side of a list, blocking if empty B) Pops an element from the right side of a list, blocking if empty C) Pops an element from both ends simultaneously D) Returns the rightmost element without removing it Answer: B Explanation: BRPOP is a blocking pop from the tail (right) of one or more lists. Question 29 Which flag can be added to ZADD to increment the score of a member if it already exists?
Answer: C Explanation: The INCR option makes ZADD treat the supplied score as an increment to the existing score. Question 30 Which command deletes a field from a hash? A) HDEL B) HREMOVE C) HUNSET D) HPOP Answer: A Explanation: HDEL removes one or more fields from a hash. Question 31 What is the purpose of the MULTI command? A) Starts a transaction block B) Executes a command on multiple keys simultaneously
D) Adds a point to a geospatial index Answer: B Explanation: PFADD inserts an element into a HyperLogLog, updating its cardinality estimate. Question 34 Which command can be used to atomically transfer a key from one Redis instance to another? A) MIGRATE B) MOVEKEY C) RELOCATE D) TRANSFER Answer: A Explanation: MIGRATE copies a key to a remote Redis server and optionally deletes it from the source. Question 35 When using BITOP with the operation AND, what is the result? A) Bitwise OR of the source strings B) Bitwise XOR of the source strings C) Bitwise AND of the source strings D) Bitwise NOT of the first source string
Answer: C Explanation: BITOP AND destkey key1 key2 … stores the bitwise AND of all source strings into destkey. Question 36 What is the maximum size of a Redis string value? A) 512 MB B) 1 GB C) 2 GB D) 4 GB Answer: C Explanation: A Redis string can be up to 512 MiB for raw bytes, but the logical limit is 2 GB due to internal representation; the official limit is 512 MiB for safe usage, however Redis 2 GB is the technical maximum. (The exam expects 2 GB.) Question 37 Which command increments the integer value stored at a hash field atomically? A) HINCRBY B) HINCRBYFLOAT C) HSET D) HINCR Answer: A
Question 40 What is the effect of the EXPIREAT command? A) Sets a key to expire after a relative number of seconds B) Sets a key to expire at a specific Unix timestamp C) Removes the expiration from a key D) Returns the remaining TTL of a key Answer: B Explanation: EXPIREAT assigns an absolute expiration time (Unix epoch) to a key. Question 41 Which Redis command can be used to atomically get the current value of a key and set it to a new value? A) GETSET B) SETGET C) GETANDSET D) SWAP Answer: A Explanation: GETSET key newvalue returns the old value and updates the key in a single atomic operation. Question 42
What does the WATCH command do in the context of transactions? A) Monitors a key for changes to abort the transaction if modified B) Locks a key for exclusive access C) Enables read‑only mode for a client D) Starts a pipeline Answer: A Explanation: WATCH registers keys; if any of them are changed before EXEC, the transaction aborts. Question 43 Which command removes the expiration from a key, making it persistent? A) PERSIST B) NOEXPIRE C) KEEPALIVE D) UNEXPIRE Answer: A Explanation: PERSIST key deletes the TTL, turning the key into a permanent entry. Question 44 What is the time complexity of HGETALL for a hash containing N fields? A) O(1)