StackExchange / StackExchange.Redis

General purpose redis client
https://stackexchange.github.io/StackExchange.Redis/
Other
5.88k stars 1.51k forks source link

Invalid Lua script evaluation #2273

Open olizarevichroman opened 1 year ago

olizarevichroman commented 1 year ago

Hi, i'm calling this simple Lua script passing Redis key to get string value, but key is passed to the ARGV collection. Also i've noticed that my key passed twice, first as an argument and then as a key. Profiler log provided below

var script = "return redis.call('get', @settingIdKey)");
var preparedScript = LuaScript.Prepare(script);

var redisResult = await database.ScriptEvaluateAsync(preparedScript, new
{
    settingIdKey = (RedisKey)"my key",
});

Profiler log:

"SCRIPT" "LOAD" "return redis.call('get', ARGV[1])"
"EVAL" "return redis.call('get', ARGV[1])" "1" "my key" "my key"
[0 lua] "get" "my key"

Based on the documentation it should treat it as a key

mgravell commented 1 year ago

Indeed, this is a side-effect of the current auto-parameterization implementation. If you want fine-grained control over the semantics, I suggest using the simple ScriptEvaluate API and passing the args/keys explicitly.

olizarevichroman commented 1 year ago

Is it supposed to be fixed? Or this "side-effect" is expected behavior?