Redis 事务 不是原子性的!

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CmdSmith/article/details/86475730

单个Redis命令的执行是原子性的,但Redis没有在事务上增加任何维持原子性的机制,所以Redis事务的执行并不是原子性

事务可以理解为一个打包的批量执行脚本但批量执行并非原子化的操作,中间某条指令的失败不会导致前面已做指令的回滚,也不会造成后续指令不做

这是官网上的说明 From redis docs on transactions:

It’s important to note that even when a command fails, all the other commands in the queue are processed – Redis will not stop the processing of commands.

比如:

test.toop.localdomain:6379> multi
OK
test.toop.localdomain:6379> set a aa
QUEUED
test.toop.localdomain:6379> set b bb
QUEUED
test.toop.localdomain:6379> set c cc
QUEUED
test.toop.localdomain:6379> exec
1) OK
2) OK
3) OK
test.toop.localdomain:6379> get a
"aa"
test.toop.localdomain:6379> get b
"bb"
test.toop.localdomain:6379> get c
"cc"
test.toop.localdomain:6379> 
test.toop.localdomain:6379> multi
OK
test.toop.localdomain:6379> set a aaa
QUEUED
test.toop.localdomain:6379> lpush b b b b b b
QUEUED
test.toop.localdomain:6379> set c ccc
QUEUED
test.toop.localdomain:6379> exec
1) OK
2) (error) WRONGTYPE Operation against a key holding the wrong kind of value
3) OK
test.toop.localdomain:6379> get a
"aaa"
test.toop.localdomain:6379> get b
"bb"
test.toop.localdomain:6379> get c
"ccc"
test.toop.localdomain:6379> 

猜你喜欢

转载自blog.csdn.net/CmdSmith/article/details/86475730