Redis 使用 'QUEUED' 回复所有查询
Redis reply all queries with 'QUEUED'
过了一会儿 运行 我的应用程序 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
command is not executed for the begin command MULTY
在同一个 redis 连接中。
这是一个例子:
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.
过了一会儿 运行 我的应用程序 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
command is not executed for the begin command MULTY
在同一个 redis 连接中。
这是一个例子:
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.