gpt4 book ai didi

c# - Redis 使用 'QUEUED' 回复所有查询

转载 作者:可可西里 更新时间:2023-11-01 11:23:20 25 4
gpt4 key购买 nike

运行我的应用一段时间后,Redis 没有回答查询,只说 QUEUED。似乎一个交易是开放的,而我在我的代码中执行所有交易。为什么交易没有完成?有没有办法检测和回滚它?

我查看了事务对象,没有丢弃、回滚或类似的东西。

问题开始时我有这个日志。

   StackExchange.Redis.RedisConnectionException: An unknown error occurred when 
writing the message
at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message
message, ResultProcessor`1 processor, ServerEndPoint server)
at StackExchange.Redis.RedisTransaction.Execute(CommandFlags flags)

当 Redis 不断回复“QUEUED”时,monitor 命令只记录 PING。

最佳答案

您的交易似乎没有正常结束。例如 EXEC 命令不会在同一个 redis 连接中为 begin 命令 MULTY 执行。

这是一个例子:

127.0.0.1:6379> MULTI                                                                                               
OK
127.0.0.1:6379> set x 123
QUEUED
127.0.0.1:6379> set y 456
QUEUED
127.0.0.1:6379> set z 678
QUEUED
127.0.0.1:6379> exec
1) OK
2) OK
3) OK

无论你在 MULTY 命令后输入了多少,它总是显示 QUEUED 直到 EXEC 命令被执行。如果有,请仔细检查您的代码

any thing missed after transaction started

或者您正在使用相同的共享 redis-connection 对象来存储值。

更新:来自评论:在 redis 中回滚是不可能的,但是通过以下方式丢弃这个事务:

> SET foo 1
OK
> MULTI
OK
> INCR foo
QUEUED
> DISCARD
OK

But the thing that I'm really looking for is that is there a way to detect and rollback it?

是的,可以检测到错误。但是redis本身并不支持回滚。来自 redis 文档:

Why Redis does not support roll backs?

If you have a relational databases background, the fact that Redis commands can fail during a transaction, but still Redis will execute the rest of the transaction instead of rolling back, may look odd to you.

However there are good opinions for this behavior:

Redis commands can fail only if called with a wrong syntax (and the problem is not detectable during the command queueing), or against keys holding the wrong data type: this means that in practical terms a failing command is the result of a programming errors, and a kind of error that is very likely to be detected during development, and not in production. Redis is internally simplified and faster because it does not need the ability to roll back. An argument against Redis point of view is that bugs happen, however it should be noted that in general the roll back does not save you from programming errors. For instance if a query increments a key by 2 instead of 1, or increments the wrong key, there is no way for a rollback mechanism to help. Given that no one can save the programmer from his or her errors, and that the kind of errors required for a Redis command to fail are unlikely to enter in production, we selected the simpler and faster approach of not supporting roll backs on errors.

关于c# - Redis 使用 'QUEUED' 回复所有查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57286118/

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