Redis 保证 XREAD return 值?

Redis guarantees on XREAD return value?

可以使用 XREAD(或其他命令)自动检测数据是否已写入 Redis 流吗?

更具体地说:

假设您在一个进程中将一些数据添加到 Redis 流中,并看到数据已使用一些自动生成的键成功添加。

XADD somestream foo bar

这个XADD完成后,你马上运行在另一个进程中读取下面的内容。

XREAD COUNT 1000 STREAMS somestream 0-0

此 XREAD 是否保证 return 数据?文档并不清楚成功的 XADD 是否保证读者会立即看到添加的数据,或者是否可能有一些小的延迟。

Redis 著名的单线程 architecture 回答了这个问题。当您在一个进程(客户端)上执行 XADD 并且在另一个进程(客户端)执行 XREAD 之后,服务器会连续执行它们,这保证了数据会在 XREAD 之前存在已执行。

接下来的引述来自The Little Redis Book

Every Redis command is atomic, including the ones that do multiple things. Additionally, Redis has support for transactions when using multiple commands.

You might not know it, but Redis is actually single-threaded, which is how every command is guaranteed to be atomic. While one command is executing, no other command will run. (We’ll briefly talk about scaling in a later chapter.) This is particularly useful when you consider that some commands do multiple things.