SETNX 是否总是在哨兵系统的redis master 上执行?
Is the SETNX always executed on redis master in the sentinel system?
想问
- 如果 SETNX 命令(NX 测试和 SET)保证在 "Redis Sentinel System" 的上下文中在 redis master 上执行?
- 如果保证在 "Redis Sentinel System" 的上下文中是原子的?
阅读文档后我的理解是两者都是肯定的,因为:
- 广告。 1 只有主机可以接受写入,因为 SETNX 有一个 set/write 组件,它必须去主机(因为所有写入都通过主机)。
- 广告。 2 因为 SET 将在主服务器上执行,所以只有在主服务器上检查 NX 部分才有意义(永远不会查询从服务器),否则会不必要地耗费时间并可能破坏原子性。
谁能 100% 肯定地确认一下,也许可以指出一些文档来消除我的疑虑。
提前致谢!
我可以以 %99.97(3 西格玛)的确定性确认以上内容。
Ad. 1 only the master can accept writes and since SETNX has a set/write component it has to go to the master (because all writes go through the master).
正确,不包括您故意启用写入副本并连接到副本的场景。
Ad. 2 since the SET will be executed on the master it only make sense to check the NX part also on the master (no slaves queried, ever), otherwise it would be unnecessarily time consuming and could undermine atomicity.
是的。
想问
- 如果 SETNX 命令(NX 测试和 SET)保证在 "Redis Sentinel System" 的上下文中在 redis master 上执行?
- 如果保证在 "Redis Sentinel System" 的上下文中是原子的?
阅读文档后我的理解是两者都是肯定的,因为:
- 广告。 1 只有主机可以接受写入,因为 SETNX 有一个 set/write 组件,它必须去主机(因为所有写入都通过主机)。
- 广告。 2 因为 SET 将在主服务器上执行,所以只有在主服务器上检查 NX 部分才有意义(永远不会查询从服务器),否则会不必要地耗费时间并可能破坏原子性。
谁能 100% 肯定地确认一下,也许可以指出一些文档来消除我的疑虑。 提前致谢!
我可以以 %99.97(3 西格玛)的确定性确认以上内容。
Ad. 1 only the master can accept writes and since SETNX has a set/write component it has to go to the master (because all writes go through the master).
正确,不包括您故意启用写入副本并连接到副本的场景。
Ad. 2 since the SET will be executed on the master it only make sense to check the NX part also on the master (no slaves queried, ever), otherwise it would be unnecessarily time consuming and could undermine atomicity.
是的。