Memecache 密钥同步
我正在使用 PHP 实现一个 Web 服务器,该服务器使用 memcache 来存储一些经常访问的数据。每个请求可能会更新 memcache 中的一个键。关键是一个数组,我的更新将向数组添加/删除一些元素。
我的问题是是否有多个请求同时到达并更新密钥。 memcache 是否提供任何类型的同步机制。
我在谷歌和这里搜索,但没有找到太多有用的信息。
最好的, 小沫
I'm implementing a web server using PHP that uses memcache to store some frequent accessed data. Each request may update one key in memcache. The key is an array and my update will add/remove some elements to/from the array.
My question is if multiple requests arrive and update the key simultaneously. Does memcache provide any kind of synchronization mechanism.
I search in Google and here, but didn't find much helpful information.
Best,
Xiaomo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要使用 cas 值才能执行此操作。其工作方式是从服务器请求密钥的 cas 编号。然后,您更新该键的值并执行包含 cas 编号的设置。如果 cas 没有改变,服务器只会更新密钥。如果有,那么您就知道其他人在您之前更新了数据,您可以再次获取密钥的值和 cas 并重试更新。
*注:我这里说的是你做一套,包括cas号。如果您查看发送的二进制数据包,这是正确的,但在大多数 sdk 和 ASCII 协议中,都有单独的 cas 函数/命令。在进行更新时,您希望使用这些而不是设置函数/操作。
要在 ASCII 协议中执行 cas,请参阅此处:
http://code.sixapart.com/svn/memcached/trunk /server/doc/protocol.txt
You will need to use cas values in order to do this. The way this works is by requesting the cas number for a key from the server. You then update the value for that key and do set which includes the cas number. The server will then only update the key if the cas has not changed. If it has then you know someone else has updated the data before you did and you can get the value and cas for the key again and retry your update.
*Note: I said here that you do a set and include the cas number. If you look at the binary packet that gets sent this is true, but in most sdk's and in the ASCII protocol there are separate cas functions/commands. You want to use these instead of set functions/operations when doing your update.
To do a cas in the ASCII protocol see here:
http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt