0
0
Redisquery~30 mins

Accessing keys and arguments in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Accessing keys and arguments in Redis Lua scripts
📖 Scenario: You are managing a Redis database for a small online store. You want to write a Lua script that can access keys and arguments passed to it, to perform operations like checking stock or updating prices.
🎯 Goal: Build a Redis Lua script that accesses keys and arguments correctly using KEYS and ARGV arrays.
📋 What You'll Learn
Create a Lua script that reads one key from KEYS
Read two arguments from ARGV
Use the key and arguments in the script logic
Return a combined string showing the key and arguments
💡 Why This Matters
🌍 Real World
Redis Lua scripts are used to perform atomic operations on Redis data by accessing keys and arguments passed from the client.
💼 Career
Understanding how to access KEYS and ARGV in Redis Lua scripts is essential for backend developers working with Redis to implement efficient and safe data operations.
Progress0 / 4 steps
1
Create a Lua script with one key in KEYS
Create a Lua script that accesses the first key from the KEYS array and stores it in a variable called productKey.
Redis
Need a hint?

Remember, KEYS is an array of keys passed to the script. Use KEYS[1] to get the first key.

2
Access two arguments from ARGV
Add code to access the first and second arguments from the ARGV array and store them in variables called arg1 and arg2.
Redis
Need a hint?

Use ARGV[1] and ARGV[2] to get the first and second arguments passed to the script.

3
Combine the key and arguments into a string
Create a variable called result that concatenates productKey, arg1, and arg2 separated by commas.
Redis
Need a hint?

Use the Lua string concatenation operator .. to join strings with commas.

4
Return the combined string from the script
Add a return statement to return the result variable from the Lua script.
Redis
Need a hint?

Use return to send the result back from the Lua script.