Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start scanning keys from the beginning.
Redis
cursor = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting cursor at 1 instead of 0.
Using None or negative numbers as cursor.
✗ Incorrect
The SCAN command starts with cursor 0 to begin iteration over keys.
2fill in blank
mediumComplete the code to scan keys matching the pattern 'user:*'.
Redis
cursor, keys = redis.scan(cursor, match=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'user*' which matches keys starting with 'user' but no colon.
Using incorrect wildcard characters like '?' or '#'.
✗ Incorrect
The pattern 'user:*' matches keys starting with 'user:' followed by anything.
3fill in blank
hardFix the error in the loop condition to continue scanning until cursor is zero.
Redis
while cursor != [1]: cursor, keys = redis.scan(cursor)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for cursor != None or -1 which are invalid.
Using cursor != 1 which causes infinite loop.
✗ Incorrect
The SCAN command returns cursor 0 when the iteration is complete.
4fill in blank
hardFill both blanks to scan keys with count 100 and match pattern 'session:*'.
Redis
cursor, keys = redis.scan(cursor, match=[1], count=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong match pattern like 'user:*'.
Setting count to 50 instead of 100.
✗ Incorrect
Use match='session:*' to filter keys and count=100 to limit keys per scan.
5fill in blank
hardFill all three blanks to safely iterate all keys and collect them in a list.
Redis
all_keys = [] cursor = [1] while cursor != [2]: cursor, keys = redis.scan(cursor, match=[3]) all_keys.extend(keys)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using None or 1 as cursor start or end condition.
Using a match pattern other than '*'.
✗ Incorrect
Start cursor at 0, loop until cursor is 0, and match '*' to get all keys.