远程登录和Java(com.danga)之间的Memcached跨客户端兼容性问题



我是memcached的新手,认识了一位老朋友Java——我正在运行带有Java 1.7的win x64。此外,通过设置文件couchbase-server-enterprise_2.2.0_x86_64在我的本地win64机器上运行couchbasememcache服务器。通常一切都很好,直到我在与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

我在看这里:http://www.geelou.com/javadocs/java_memcached-release_2.0.1/com/danga/MemCached/MemCachedClient.html但我没有看到任何关于hashCode的解释,也没有看到它是否对应于memcached服务器中的相同标志/元数据参数。

我想我的问题大致可以归结为:com.danga get命令hashCode参数值是否可以从32更改,以便在如上所示使用metadata/flag 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用python为String集获取null,然后从Java获取,我可以使用解决我的问题

mcca.setPrimitiveAsString(true);
mcca.setSanitizeKeys(false);
pool.setHashingAlg(SockIOPool.NEW_COMPAT_HASH);

但我仍然不明白为什么会出现这种差异,以及我是否/如何修改调用以获得参数来修复它

注意事项:将flag/metadata参数设置为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?

我认为问题是您的"flag"参数告诉您的库数据存储方式不同。我不知道为什么要在telnet SET命令中指定"1"one_answers"32",但您可能想用指定的不同标志值来测试它。

您指定的"1"one_answers"32"通常由客户端库用来指定数据的格式。它们不是哈希值。

我认为您混合了参数。

Telnet:

set key metaData expiryTime lengthInBytes
set s1     1        0             4

Java:

https://github.com/gwhalin/Memcached-Java-Client

mc.get(key, hash); // <- retrieves key by hash
mc.keyExists(key);
mc.get(key, null, true);

https://github.com/gwhalin/Memcached-Java-Client/blob/master/src/com/meetup/memcached/MemcachedClient.java#L1237

最新更新