'(error) ERR Error 运行 script (call to ...)' when using --eval for LUA 脚本
'(error) ERR Error running script (call to ...)' when using --eval for LUA script
我在 运行 这个命令时收到一条错误消息:
redis-cli --eval myscript.lua myzset 3 "one"
错误信息:
(error) ERR Error running script (call to f_9c623c243d74e75a4fe64de7a6826b47f8d7
d400): @user_script:1: @user_script: 1: Lua redis() command arguments must be st
rings or integers
Lua 脚本:
local ans = redis.call('ZINCRBY', KEYS[1], ARGV[1], ARGV[2])
if tonumber(ans) <= 0 then
redis.call('ZREM', KEYS[1], ARGV[2])
end
return (tonumber(ans) < 1 and '-1' or ans)
目标是使用 ZINCRBY
.
自动删除零值或负值
我正在使用:
Windows 7 64bit
Redis Version: 3.2.100
我们将不胜感激。
您遇到的问题是因为您没有将 KEYS 和 ARGS 分开 - 在命令行中使用逗号来做到这一点。另外请注意,由于逗号是分隔符,因此您需要使用额外的 space 以确保它不被视为密钥的一部分。
像这样:
redis-cli --eval myscript.lua myzset , 3 "one"
我在 运行 这个命令时收到一条错误消息:
redis-cli --eval myscript.lua myzset 3 "one"
错误信息:
(error) ERR Error running script (call to f_9c623c243d74e75a4fe64de7a6826b47f8d7
d400): @user_script:1: @user_script: 1: Lua redis() command arguments must be st
rings or integers
Lua 脚本:
local ans = redis.call('ZINCRBY', KEYS[1], ARGV[1], ARGV[2])
if tonumber(ans) <= 0 then
redis.call('ZREM', KEYS[1], ARGV[2])
end
return (tonumber(ans) < 1 and '-1' or ans)
目标是使用 ZINCRBY
.
我正在使用:
Windows 7 64bit Redis Version: 3.2.100
我们将不胜感激。
您遇到的问题是因为您没有将 KEYS 和 ARGS 分开 - 在命令行中使用逗号来做到这一点。另外请注意,由于逗号是分隔符,因此您需要使用额外的 space 以确保它不被视为密钥的一部分。
像这样:
redis-cli --eval myscript.lua myzset , 3 "one"