Redis 在命令执行时(实际上)单线程运行,因此每个命令都以原子方式执行——完整地执行,没有来自其他客户端的交错。这种原子性与原子复合命令相结合,是正确使用 Redis 进行计数器、锁和并发敏感操作的基础。
单线程 → 原子命令
Redis executes commands ONE AT A TIME (single-threaded command processing):
→ each command runs to completion before the next starts
→ NO two commands interleave → every command is inherently ATOMIC
→ no race conditions WITHIN a single command
→ This simplicity is a feature: predictable, atomic operations without locks.
原子计数器(关键优势)
INCR page:views
INCRBY downloads 5
