I have a database on Redis with the following previous registred values:
person:1 {city city:1 }
city:1 {name Brasilia}
And I have a Lua script to get the city name of a given person:
redis.call("SELECT", 5)
local attribute = redis.call("HMGET", KEYS[1], ARGV[1])
local value = redis.call("HMGET", attribute, "name")
return value
Where the KEYS[1] should have the person key, and ARGV[1] the attribute of that person, in that specific case I assume that it is the city.
But when I execut the script with the comand:
$ redis-cli --eval redis_script.lua person:1 , city
I receive the following error:
(error) ERR Error running script (call to f_8b79864f056e62eadd87b14b98e43c3457971911): @user_script:3: @user_script: 3: Lua redis() command arguments must be strings or integers
Meaning an error on the 3rd line of my script on redis.call, which I assume that is because "attribute" value is invalid. So I changed my script to find out the value of "attribute":
redis.call("SELECT", 5)
local attribute = redis.call("HMGET", KEYS[1], ARGV[1])
return attribute
Which returns:
redis-cli --eval redis_script.lua person:1 , city
1) "city:1"
And changed again to:
redis.call("SELECT", 5)
local attribute = redis.call("HMGET", KEYS[1], ARGV[1])
local value = redis.call("HMGET", "city:1", "name")
return value
Which gives me:
redis-cli --eval another_test.lua person:1 , city
1) "Brasilia"
That is what I want. But I don't get why my first code gives error on redis.call, since the "attribute" value is correct, that is, "city:1".