redis设计与实现 书中说:
Redis的事务总是具有ACID中的原子性、一致性和隔离性,当服务器运行在AOF
持久化模式下,并且appendfsync选项的值为always时,事务也具有耐久性。
可看网上资料,又说redis事务不满足原子性和持久性:
在redis事务中如果有某一条命令执行失败,其后的命令仍然会被继续执行,并不会自动回滚;
在AOF的“总是 SYNC ”模式下,事务的每条命令在执行成功之后,都会立即调用fsync或fdatasync将事务数据写入到AOF文件。
但是,这种保存是由后台线程进行的,主线程不会阻塞直到保存成功,所以从命令执行成功到数据保存到硬盘之间,还是有一段非常小的间隔,所以这种模式下的事务也是不持久的。
求解答~~
This is mainly due to doubts about the atomicity of redis. Now it has been verified that redis does not ensure atomicity. When the command execution fails in the transaction, it will not be rolled back.
First of all, redis is single-threaded, so there is actually no concept of transactions, unless you use mutil to manually encapsulate a set of commands together and execute them as a whole. Specifically, if one instruction in the whole fails, will it be rolled back? You can do it yourself Take a test.
Single-threaded, so each command is atomic. Consistency and isolation are for transactions. Redis transactions are executed by encapsulating a group of commands together, so they are isolated because they block other commands. Execution, as for consistency, if the test you do above will roll back, then it is consistent, if it does not roll back, then it is not consistent.