从 Lua 调用 Redis 时出现语法错误

Syntax error when making Redis call from Lua

Redis 5.0 中尝试使用来自 Lua 的可选参数 LT 执行 ZADD 时出现语法错误 ( @user_script:15: ERR syntax error)。 12:

redis.call('zadd', ASET, 'lt', 100, "A")

但相同的代码在 Redis 6.2.1

上运行良好

在旧版本的 Redis 中是否有一些替代方法来传递可选参数?

它在 Redis 5.0.12 中不起作用,因为您正在使用直到 Redis 6.2 才添加的功能(LT 选项)。来自 ZADDdocumentation:

>= 6.2: Added the GT and LT options

来自

Was there a way in 5.x to add to ZSET only elements that are not already present regardless of the score?

ZADDNX 选项似乎符合您的要求。

NX: Don't update already existing elements. Always add new elements.

因此,即使使用 Redis,以下代码也应该可以正常工作 5.x

redis.call('zadd', ASET, 'nx', 100, "A")