redis 中的流水线与事务 [英] pipelining vs transaction in redis

查看:58
本文介绍了redis 中的流水线与事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们在 Redis 中使用事务时,它基本上将事务中的所有命令进行流水线处理.而当EXEC被触发时,则所有的命令一起执行,从而始终保持多条命令的原子性.

When we use a transaction in Redis, it basically pipelines all the commands within the transaction. And when EXEC is fired, then all the commands are executed together, thus always maintaining the atomicity of multiple commands.

这和流水线不一样吗?

流水线和事务有何不同?另外,为什么 Redis 的单线程特性还不够?为什么我们明确需要流水线/事务?

How are pipelining and transaction different? Also, why does not the single threaded nature of Redis suffice? Why do we explicitly need pipelining/transaction?

推荐答案

流水线主要是一种网络优化.它本质上意味着客户端缓冲一堆命令并将它们一次性发送到服务器.不保证在事务中执行命令.这里的好处是为每个命令节省网络往返时间.

Pipelining is primarily a network optimization. It essentially means the client buffers up a bunch of commands and ships them to the server in one go. The commands are not guaranteed to be executed in a transaction. The benefit here is saving network round trip time for every command.

Redis 是单线程的,因此单个命令始终是原子的,但是来自不同客户端的两个给定命令可以按顺序执行,例如在它们之间交替执行.

Redis is single threaded so an individual command is always atomic, but two given commands from different clients can execute in sequence, alternating between them for example.

但是,Multi/exec 可确保在 multi/exec 序列中的命令之间没有其他客户端正在执行命令.

Multi/exec, however, ensures no other clients are executing commands in between the commands in the multi/exec sequence.

这篇关于redis 中的流水线与事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆