Do memcache clients of different languages hash the same way?

筅森魡賤 提交于 2019-12-05 04:42:07

No. Not all clients hash the same way. As evidence of this, you'll see that some clients offer "consistent hashing", while others don't.

In short, memcached clients are allowed to use any hashing algo they please. There is no official standard.

The PHP client supports a variety of hashing algorithms -- so it may be possible to configure it to use the same algo your Java library uses (it looks like there are several out there -- which are you using?). But you'll want to test heavily, obviously.

Another possibility to allow cross-language access would be to not rely on the language serialization but store objects in JSON format, as String of text.

Personally, I use Gson for Java and the json_encode, json_decode in PHP.

pylibmc

import pylibmc

mc = pylibmc.Client(["127.0.0.1"], binary=True,
                   behaviors={"tcp_nodelay": True,
                               "ketama": True})

key="someKey"
i=0
while True:
    #mc.set(key, str(i))
    value = mc.get(key)
    print(value)
    sleep(1)
    i+=1
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!