本文介绍了Redis的set命令是原子操作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Redis的set
命令实现最简单的分布式锁组件,但是我无法通过官方文档找到关于原子性的确切依据,Redis的SET key value [EX seconds] [PX milliseconds] [NX|XX]
命令是原子操作吗?
I'm trying to use Redis' set
command to implement a simplest distributed lock component, but I can't find any exact basis about atomicity through the official document, is Redis' SET key value [EX seconds] [PX milliseconds] [NX|XX]
command an atomic operation?
推荐答案
是.核心是单线程的,因此什么都不会运行,直到SET
完成为止.使得SET {key} {value} EX {expiry} NX
非常适合简单锁定.
Yes. The core is single threaded, so nothing will run until the SET
has completed; that makes SET {key} {value} EX {expiry} NX
ideal for simple locking.
这篇关于Redis的set命令是原子操作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!