0
0
Redisquery~20 mins

Accessing keys and arguments in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Keys and Arguments Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Accessing KEYS and ARGV in a Lua script
Given the following Redis Lua script, what will be the output if KEYS = ['user:1', 'user:2'] and ARGV = ['100', '200']?

return {KEYS[1], ARGV[2]}
Redis
return {KEYS[1], ARGV[2]}
A["user:1", "200"]
B["user:2", "100"]
C["user:1", "100"]
D["user:2", "200"]
Attempts:
2 left
💡 Hint
Remember that KEYS and ARGV are 1-based indexed in Redis Lua scripts.
🧠 Conceptual
intermediate
2:00remaining
Understanding KEYS and ARGV usage in Redis scripts
Why does Redis separate input parameters into KEYS and ARGV in Lua scripts?
ATo allow passing only keys without any arguments.
BTo optimize memory usage by separating keys and arguments.
CTo distinguish keys that will be accessed for locking and replication from other arguments.
DTo enforce that keys must be strings and arguments must be numbers.
Attempts:
2 left
💡 Hint
Think about Redis cluster and command atomicity.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in accessing KEYS and ARGV
Which option contains a syntax error when trying to access the first key and first argument in a Redis Lua script?
Redis
return {KEYS[0], ARGV[1]}
Areturn {KEYS[1], ARGV[1]}
Breturn {KEYS[0], ARGV[1]}
Creturn {KEYS[1], ARGV[0]}
Dreturn {KEYS[1], ARGV[2]}
Attempts:
2 left
💡 Hint
Lua arrays start at 1, not 0.
🔧 Debug
advanced
2:00remaining
Debugging argument access in Redis Lua script
A Redis Lua script returns nil when trying to access ARGV[3], but ARGV has 2 elements. What is the cause?
AARGV is empty because KEYS were passed instead.
BARGV indexing starts at 0, so ARGV[3] is invalid.
CARGV must be accessed with string keys, not numeric indices.
DARGV[3] is out of range because only 2 arguments were passed.
Attempts:
2 left
💡 Hint
Check how many arguments are passed in ARGV.
optimization
expert
2:00remaining
Optimizing Redis Lua script argument usage
You have a Redis Lua script that receives 10 keys and 10 arguments. You only need to access the first 3 keys and first 5 arguments. Which approach is best for performance?
APass only the needed keys and arguments to the script to reduce input size.
BLoop over all 10 KEYS and 10 ARGV and ignore unused ones.
CCopy KEYS and ARGV into new tables with only needed elements before use.
DAccess only KEYS[1] to KEYS[3] and ARGV[1] to ARGV[5] directly without looping over all.
Attempts:
2 left
💡 Hint
Minimize data passed to the script for best performance.