Challenge - 5 Problems
Redis APPEND Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the result of APPEND command?
Given a Redis key
greeting with value "Hello", what will be the value of greeting after executing APPEND greeting " World"?Redis
SET greeting "Hello" APPEND greeting " World" GET greeting
Attempts:
2 left
💡 Hint
APPEND adds the new string to the end of the existing string.
✗ Incorrect
The APPEND command adds the specified string to the end of the existing string value stored at the key. So " World" is appended to "Hello", resulting in "Hello World".
❓ query_result
intermediate1:30remaining
What does APPEND return?
If the key
name has value "Redis", what does the command APPEND name "DB" return?Redis
SET name "Redis" APPEND name "DB"
Attempts:
2 left
💡 Hint
APPEND returns the length of the new string after appending.
✗ Incorrect
APPEND returns the length of the string after the append operation. "Redis" has length 5, appending "DB" adds 2 characters, total length 7.
📝 Syntax
advanced1:30remaining
Identify the syntax error in APPEND usage
Which of the following APPEND commands will cause a syntax error in Redis?
Attempts:
2 left
💡 Hint
APPEND requires exactly two arguments: key and value.
✗ Incorrect
Option B is missing the second argument (the string to append), causing a syntax error. Options A, C, and D are valid syntax (quotes optional for keys and values in Redis CLI).
🧠 Conceptual
advanced1:30remaining
What happens if APPEND is used on a non-string key?
If the key
counter holds an integer value (stored as a string) and you run APPEND counter "1", what will happen?Redis
SET counter "100" APPEND counter "1" GET counter
Attempts:
2 left
💡 Hint
Redis stores all strings as strings, even numbers are strings.
✗ Incorrect
Redis treats all values as strings. APPEND concatenates the string "1" to "100", resulting in "1001". No type error occurs.
❓ optimization
expert2:00remaining
Efficiently concatenate multiple strings using APPEND
You want to concatenate the strings "a", "b", "c", "d" to an empty Redis key
letters. Which sequence of commands is the most efficient to get the final value "abcd"?Attempts:
2 left
💡 Hint
APPEND adds to existing string; SET overwrites.
✗ Incorrect
Option C sets the entire string at once, which is the most efficient. Option C works because APPEND on a non-existing key treats it as empty, so first APPEND "a" creates "a" but involves multiple commands. Option C initializes the key with "a" and then appends "b", "c", "d" sequentially, resulting in "abcd" but with more commands. Option C overwrites the key each time, ending with "d" only.