[{"id":"redisbeginner-001","courseId":"redis-beginner","domain":"data-structures","topic":"Overwriting a string with SET","prompt":"A teammate caches a cart id with a 60 second expiry. Ten seconds later the same key is written again with a plain SET, no options. What is true of the key now?","hint":"A plain SET replaces the value; think about what happens to the old expiry.","source":"https://redis.io/docs/latest/commands/set/","interaction":{"type":"single"},"options":[{"id":"a","text":"It holds cart-2, and the key no longer has an expiry.","why":"SET overwrites the old value regardless of its type, and any previous time to live is discarded unless KEEPTTL is given."},{"id":"b","text":"It holds cart-2, and still expires 50 seconds from now.","whyNot":"The old TTL is not carried over: a successful plain SET discards it."},{"id":"c","text":"It still holds cart-1, because the key already exists.","whyNot":"SET overwrites an existing value; NX is the option that refuses to touch an existing key."},{"id":"d","text":"It holds both values until the first one expires.","whyNot":"A string key holds a single value; the second write replaces the first."}],"answer":"a","explanation":"SET sets the string value of a key and creates the key if needed. If the key already holds a value it is overwritten, regardless of its type, and any previous time to live is discarded.","concept":"SET sets the string value of a key and creates the key if needed. If the key already holds a value it is overwritten, regardless of its type, and any previous time to live is discarded.","rev":1,"kind":"scenario","code":"SET session:42 \"cart-1\" EX 60\nSET session:42 \"cart-2\"","takeaways":["A plain SET drops the old TTL; add KEEPTTL if the expiry must survive."]},{"id":"redisbeginner-002","courseId":"redis-beginner","domain":"data-structures","topic":"Incrementing a missing key","prompt":"A counter key visits:2026-10-22 has never been written. A worker runs INCR on it. What comes back?","hint":"A missing key is treated as zero before the increment.","source":"https://redis.io/docs/latest/commands/incr/","interaction":{"type":"single"},"options":[{"id":"a","text":"1, and the key is created holding the string \"1\".","why":"If the key does not exist it is set to 0 first, then incremented, so the reply is 1 and the result is stored."},{"id":"b","text":"0, and the key is created holding \"0\".","whyNot":"The increment happens after the key is initialised, so the stored value is 1."},{"id":"c","text":"An error, because INCR needs an existing integer.","whyNot":"A missing key is not an error; only a wrong type or a non-integer string is."},{"id":"d","text":"Nil, and nothing is stored.","whyNot":"INCR always returns the new integer value and always writes it."}],"answer":"a","explanation":"INCR increments the number stored at a key by one. If the key does not exist, it is set to 0 before the operation, so the first call returns 1.","concept":"INCR increments the number stored at a key by one. If the key does not exist, it is set to 0 before the operation, so the first call returns 1.","rev":1,"kind":"scenario","code":"INCR visits:2026-10-22","takeaways":["A first INCR creates the key at 1, so counters need no initialisation."]},{"id":"redisbeginner-003","courseId":"redis-beginner","domain":"data-structures","topic":"Pushing to the head of a list","prompt":"A queue is empty. A worker runs LPUSH jobs a b c as a single command. What does LRANGE jobs 0 -1 show afterwards?","hint":"Each element is prepended in turn, left to right.","source":"https://redis.io/docs/latest/commands/lpush/","interaction":{"type":"single"},"options":[{"id":"a","text":"c, b, a","why":"Elements are inserted one after another at the head, from the leftmost argument to the rightmost, so the last argument ends up first."},{"id":"b","text":"a, b, c","whyNot":"That is the order RPUSH would produce by appending each element at the tail."},{"id":"c","text":"b, a, c","whyNot":"There is no reordering by value; each new element simply becomes the new head."},{"id":"d","text":"An error, because LPUSH accepts only one element.","whyNot":"LPUSH accepts multiple elements in one call, since Redis 2.4.0."}],"answer":"a","explanation":"LPUSH inserts all given values at the head of a list, creating the key if needed. Multiple elements are inserted one after the other from left to right, so LPUSH mylist a b c leaves c first, b second and a third.","concept":"LPUSH inserts all given values at the head of a list, creating the key if needed. Multiple elements are inserted one after the other from left to right, so LPUSH mylist a b c leaves c first, b second and a third.","rev":1,"kind":"scenario","code":"LPUSH jobs a b c\nLRANGE jobs 0 -1","takeaways":["With several arguments, the last one passed to LPUSH becomes the new head."]},{"id":"redisbeginner-004","courseId":"redis-beginner","domain":"data-structures","topic":"Negative list indexes","prompt":"A list tasks holds build, test, deploy in that order. A teammate runs LRANGE tasks -2 -1 to fetch the last two items. What comes back?","hint":"Negative offsets count from the tail, and both ends are included.","source":"https://redis.io/docs/latest/commands/lrange/","interaction":{"type":"single"},"options":[{"id":"a","text":"test and deploy","why":"Negative offsets start at the end: -1 is the last element and -2 the penultimate, and stop is inclusive."},{"id":"b","text":"build and test","whyNot":"Negative indexes count from the tail, not from the head; -2 is not the second element."},{"id":"c","text":"test only","whyNot":"The stop index is inclusive, so the element at -1 is returned as well."},{"id":"d","text":"An empty array, because -2 is out of range","whyNot":"Negative indexes are valid, and out-of-range indexes are treated as the nearest end, not as an error."}],"answer":"a","explanation":"LRANGE uses zero-based indexes, and negative offsets count from the end of the list: -1 is the last element, -2 the penultimate, and so on. Both start and stop are inclusive.","concept":"LRANGE uses zero-based indexes, and negative offsets count from the end of the list: -1 is the last element, -2 the penultimate, and so on. Both start and stop are inclusive.","rev":1,"kind":"scenario","code":"RPUSH tasks build test deploy\nLRANGE tasks -2 -1","takeaways":["LRANGE tasks -2 -1 returns the final two elements, in list order."]},{"id":"redisbeginner-005","courseId":"redis-beginner","domain":"data-structures","topic":"Updating hash fields","prompt":"HSET user:7 name \"Ada\" has already run. A teammate then runs HSET user:7 name \"Grace\". What does that second call return, and what does HGET user:7 name give?","hint":"HSET both writes the value and reports what it added.","source":"https://redis.io/docs/latest/commands/hset/","interaction":{"type":"single"},"options":[{"id":"a","text":"0, and Grace","why":"An existing field's value is overwritten, and the reply counts only fields that were newly added, which is none here."},{"id":"b","text":"0, and Ada","whyNot":"The reply is 0, but the value is still replaced: HSET overwrites existing fields."},{"id":"c","text":"1, and Grace","whyNot":"No new field was created, so the count is 0 even though the value changed."},{"id":"d","text":"1, and Ada","whyNot":"Nothing new was added and the old value is not kept; both parts of this option are wrong."}],"answer":"a","explanation":"HSET sets fields in a hash, overwriting the values of fields that already exist and creating the key if it does not exist. Its reply is the number of fields that were added, not the number updated.","concept":"HSET sets fields in a hash, overwriting the values of fields that already exist and creating the key if it does not exist. Its reply is the number of fields that were added, not the number updated.","rev":1,"kind":"scenario","code":"HSET user:7 name \"Ada\"\nHSET user:7 name \"Grace\"\nHGET user:7 name","takeaways":["HSET updating an existing field returns 0; only new fields are counted."]}]