开发者问题收集

从 Lua 脚本调用的未知 Redis 命令

2019-04-09
3939

我尝试使用“config get”命令在 lua 中获取 redis 状态指标之一,但收到“从 Lua 脚本调用的未知 Redis 命令”的错误提示,我不知道为什么?

127.0.0.1:6379> eval "return redis.call('config get','lazyfree_pending_objects')" 0
(error) ERR Error running script (call to f_4e7351811a87a6961eb6fe85622dce826bbc681c): @user_script:1: @user_script: 1: Unknown Redis command called from Lua script
127.0.0.1:6379> eval "return redis.call('config', 'get','lazyfree_pending_objects')" 0
(empty list or set)
127.0.0.1:6379> eval "return redis.call('config', 'get','used_memory_dataset')" 0
(empty list or set)
127.0.0.1:6379> eval "return redis.call('config', 'get used_memory_dataset')" 0
(error) ERR Error running script (call to f_25423fef37dc24142677d59a564f5b664f9e0f45): @user_script:1: ERR CONFIG subcommand must be one of GET, SET, RESETSTAT, REWRITE
2个回答

你的代码有两个问题。

对于 config get xxxconfig 是命令, get 是子命令, xxx 是配置字段。因此,当你使用 Lua 脚本调用它时,你应该使用 redis.call('config', 'get', 'xxx')

如果你以 redis.call('config get', 'xxx') 的形式调用它,Redis 会将 config get 作为命令,这是一个 未知命令 。如果你以 redis.call('config', 'get xxx') 的方式调用,Redis 会把 get xxx 当做子命令,这也是无效的。

另外一个问题是, lazyfree_pending_objectsused_memory_dataset 不是配置,而是系统信息,你应该使用 INFO 命令。

for_stack
2019-04-09

我也遇到了同样的问题。这个问题在我将 python redis==2.10.5 升级到 redis==3.5.3 后开始出现。

我猜是因为最新的 python redis 包不支持 Redis 服务器(Linux 包)版本。

我已经将 linux Redis 服务器包升级到 4.0.9,它可以正常工作。

记得重启系统。

user1012513
2020-06-29