gpt4 book ai didi

redis - 尝试调用 'replicate_commands'字段(一个nil值)

转载 作者:行者123 更新时间:2023-12-03 06:42:44 26 4
gpt4 key购买 nike

我使用jedis + lua评估脚本,这是我的lua脚本:


redis.replicate_commands()
local second = redis.call('TIME')[1]
local currentKey = KEYS[1]..second
if redis.call('EXISTS', currentKey) == 0 then
redis.call('SETEX', currentKey, 1, 1)
return 1
else
return redis.call('INCR', currentKey)
end


当我使用“时间”时,它报告错误: 在不确定性命令之后不允许写入命令。
在互联网上搜索后,我将'redis.replicate_commands()'添加为lua脚本的第一行,但它仍然报告错误: ERR运行脚本时出错(调用f_c89a6ee8ad732a325e530f4a69226851cde302e2):@user_script:1:user_script:1:尝试调用字段'replicate_commands'(nil值)
replicate_commands是否需要自变量,或者有办法解决我的问题?

Redis版本:3.0

jedis版本:2.9

lua版本:我不知道在哪里找到

最佳答案

尝试调用字段“replicate_commands”(nil值)时发生错误,这意味着replicate_commands()对象中不存在redis。这是Lua端的错误消息。

引入replicate_commands()直到Redis 3.2。参见EVAL - Replicating commands instead of scripts。考虑升级。

第一条错误消息(,在不确定性命令之后不允许写入命令)是redis端消息,在调用非确定性命令(例如SPOP,SCAN等)后,您将无法调用写入命令(例如SET,SETEX,INCR等) ,RANDOMKEY,TIME等)。

A very important part of scripting is writing scripts that are pure functions. Scripts executed in a Redis instance are, by default, propagated to replicas and to the AOF file by sending the script itself -- not the resulting commands.



因此,如果重新启动Redis服务器,再次播放AOF日志或在从属服务器中进行复制,则脚本应提供相同的数据集。

这就是为什么在Redis 3.2中引入了replicate_commands()的原因。从Redis 5开始,脚本始终作为效果复制-就像脚本启动时调用了replicate_commands()一样。但是对于3.2之前的版本,您根本无法做到这一点。

因此,要么升级到3.2或更高版本,要么从客户端将已经计算出的currentKey传递给脚本。

请注意,动态创建currentKey将使脚本仅具有单实例功能。

All Redis commands must be analyzed before execution to determine which keys the command will operate on. In order for this to be true for EVAL, keys must be passed explicitly. This is useful in many ways, but especially to make sure Redis Cluster can forward your request to the appropriate cluster node.

Note this rule is not enforced in order to provide the user with opportunities to abuse the Redis single instance configuration, at the cost of writing scripts not compatible with Redis Cluster.



最后,Redis 3.0.0的Lua版本是Lua 5.1.5,与Redis 6 RC1之前的版本相同。

关于redis - 尝试调用 'replicate_commands'字段(一个nil值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59809151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com