我对memcached很陌生,并且认识了一个老朋友,Java -正在使用Java1.7在win x64上运行。还通过设置文件couchbase- server -enterprise_2.2.0_x86_64在本地win 64计算机上运行couchbase memcache服务器。所有操作通常都很好,直到我注意到在与telnet会话中的键集进行字符串比较并在java中检查这个键时,出现了一种奇怪的行为。
来自telnet会话
set s1 1 0 4
abcd
STORED
set s2 32 0 4
abcd
STORED我的主要java测试类:.
System.out.println("Get s1 from Cache:" +mcca.get("s1"));
System.out.println("Get s1 from Cache:" +mcca.get("s1",1));
System.out.println("Get s1 from Cache:" +mcca.get("s1",32));
System.out.println("Get s1 from Cache:" +mcca.get("s1",77, true));
System.out.println("Get s2 a from Cache:" +mcca.get("s2"));
System.out.println("Get s2 b from Cache:" +mcca.get("s2",1));
System.out.println("Get s2 c from Cache:" +mcca.get("s2",32));
System.out.println("Get s2 c from Cache:" +mcca.get("s2",77, true));输出
Get s1 from Cache:97
Get s1 from Cache:97
Get s1 from Cache:97
com.danga.MemCached.MemCachedClient Mon Dec 30 11:50:06 EST 2013 - ++++ retrieving object and stuffing into a string.
Get s1 from Cache:abcd
Get s2 a from Cache:abcd
Get s2 b from Cache:abcd
Get s2 c from Cache:abcd
com.danga.MemCached.MemCachedClient Mon Dec 30 11:50:06 EST 2013 - ++++ retrieving object and stuffing into a string.
Get s2 c from Cache:abcd我在这里查看:2.0.1/com/danga/MemCached/MemCachedClient.html,但是我没有看到关于hashCode的任何解释,也没有看到它是否对应于memcached服务器中相同的标志/元数据参数。
我认为我的问题大致可以归结为:可以将com.danga get命令hashCode参数值从32更改为当我用元数据/标志1设置s1键时,可以得到完整的字符串,如上面所示,而不必指定asString标志或mcca.setPrimitiveAsString(true)?
以及相关的,为什么
System.out.println("Get s2 a from Cache:" +mcca.get("s2")); 打印abcd的正确值,而两者都不打印:
System.out.println("Get s1 from Cache:" +mcca.get("s1"));
System.out.println("Get s1 from Cache:" +mcca.get("s1",1));打印什么似乎是正确的价值abcd?
正如在这个答案中所说的,Memcached getting null for String set with python and then get from Java,我可以使用
mcca.setPrimitiveAsString(true);
mcca.setSanitizeKeys(false);
pool.setHashingAlg(SockIOPool.NEW_COMPAT_HASH);但是,我仍然不明白为什么会出现这种差异,以及是否/如何修改调用以获得参数来修复它。
注意:将标志/元数据参数设置为32的原因是在我运行的另一个java测试中。
System.out.println("set 1 status:" + mcc.set("1", "Modified"));
//which outputs
com.danga.MemCached.MemCachedClient Fri Dec 27 00:12:51 EST 2013 - ++++ memcache cmd (result code): set 1 32 0 8
(STORED)这似乎表明com.danga库使用的标志/元数据值为32。
我想我的问题归结为来自memcache telnet会话的。
set s1 1 0 4
abcd
set s2 32 0 4
abcd 来自java的为什么
mcca.get("s1")// only gives the first ascii character code (97)
mcca.get("s2")// but gives the entire string. What is so special about the second memcache command using the hash of 32?发布于 2014-04-01 14:34:18
我认为问题在于,您的“标志”参数告诉您的库,数据是以不同方式存储的。我不知道为什么要在telnet SET命令中指定"1“和"32”,但是您可能想用指定的不同的标志值来测试它。
客户端库经常使用您指定的"1“和"32”来指定数据的格式。它们不是散列值。
发布于 2014-04-01 14:46:25
我想你把参数搞混了。
Telnet:
set key metaData expiryTime lengthInBytes
set s1 1 0 4爪哇:
https://github.com/gwhalin/Memcached-Java-Client
mc.get(key, hash); // <- retrieves key by hash
mc.keyExists(key);
mc.get(key, null, true);https://stackoverflow.com/questions/20844266
复制相似问题