0
0
Redisquery~10 mins

SCAN for safe key iteration in Redis - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start scanning keys from the beginning.

Redis
cursor = [1]
Drag options to blanks, or click blank then click option'
ANone
B0
C-1
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Starting cursor at 1 instead of 0.
Using None or negative numbers as cursor.
2fill in blank
medium

Complete 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'
A'user*'
B'user#*'
C'user:*'
D'user?*'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'user*' which matches keys starting with 'user' but no colon.
Using incorrect wildcard characters like '?' or '#'.
3fill in blank
hard

Fix 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'
A0
B-1
CNone
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for cursor != None or -1 which are invalid.
Using cursor != 1 which causes infinite loop.
4fill in blank
hard

Fill 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'
A'session:*'
B50
C100
D'user:*'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong match pattern like 'user:*'.
Setting count to 50 instead of 100.
5fill in blank
hard

Fill 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'
A0
BNone
C'*'
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using None or 1 as cursor start or end condition.
Using a match pattern other than '*'.