get_multi / set_multi 原子性?
在 Memcached 的官方常见问题解答中,我读到:
“发送到 memcached 的所有单独命令都是绝对是原子的。”
然而,当涉及到 get_multi
和 set_multi
时,我仍然不清楚。我想知道 get_multi
和 set_multi
在以下意义上是否是原子的:
- set_multi 执行的所有写入都将原子地一起执行。
- get_multi 执行的所有读取都将以原子方式一起执行。
例如,这些情况应该是不可能的:
1)
- 最初缓存的内容是
{'a': 0, 'b': 0}
- 机器 A 调用
set_multi({'a': 1 , 'b': 1})
- 机器 B 调用
get_multi(['a', 'b'])
并接收{'a': 1, 'b': 0}
2)
- 最初缓存内容为
{'a': 0, 'b': 0}
- 机器 A 调用 `set({'a': 1})
- 机器 A调用 `set({'b': 2})
- 机器 B 调用
get_multi(['a', 'b'])
并接收{'a': 0, 'b': 2}
这个问题对我的设计非常重要,我想我最好寻求确认。
In the official FAQ of Memcached i read:
"All individual commands sent to memcached are absolutely atomic."
However this is still unclear to me when it comes to get_multi
and set_multi
. I'd like to know whether get_multi
and set_multi
are atomic in the following sense:
- All writes performed by set_multi will be performed together atomically.
- All reads performed by get_multi will be performed together atomically.
For example these situations should be impossible:
1)
- Initially contents of the cache is
{'a': 0, 'b': 0}
- machine A calls
set_multi({'a': 1, 'b': 1})
- machine B calls
get_multi(['a', 'b'])
and receives{'a': 1, 'b': 0}
2)
- Initially contents of the cache is
{'a': 0, 'b': 0}
- machine A calls `set({'a': 1})
- machine A calls `set({'b': 2})
- machine B calls
get_multi(['a', 'b'])
and receives{'a': 0, 'b': 2}
This question is just so important for my design, that I thought I'd better ask for confirmation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我阅读本节时,
get_multi
出现问题并行运行的多个请求,其想法是,对于大型请求,get_multi
允许减少获取所有结果的总时间。我没有看到任何保证或提及,一起完成的独立请求总体上是原子的。相同的规则可能适用于set_multi
(即各个请求是原子的,但它们的集合不是)。似乎也没有提及交易。
As I read this section,
get_multi
issues multiple requests that run in parallel, the idea being that for large requests,get_multi
allows the total amount of time to get all results to be reduced. I don't see any guarantee or mention that the independent requests, done together, are collectively atomic. The same rule likely applies toset_multi
(i.e. the individual requests are atomic, but the collection of them is not).There also appears to be no mention of transactions.