memcached是一个高性能分布式缓存系统,java一般通过xmemcached客户端实现与服务器端的数据交互,下面看一个奇怪的问题,代码如下:
最开始我的是memecached1.2.1,xmemcached2.0.0。运行main方法后报错,如下:
错误的意思就是说 gets()方法调用是 无效的命令。如是网上查了一大堆就是没有解释这个错误是如何产生的,也没有说如何解决,可能是我搜索的方法不对,这个问题卡了好久,后来实在想不到就找了另外一台装有memcached的测试机测试,一下子通过了,如是把自己本机的memcached卸载掉重新把测试机上的版本拿过来装一遍,之后在测试也通过的,最后的问题症结在于:[color=red]当xmemcached版本是比较新的时候,memecached的版本也必须升级,必须是在memecached1.2.1以上的版本,新版的xmemcached在实现上有所改动,目前本地上我的是memecached1.4.4-14,xmemcached2.0.0[/color]
]
public static void main(String[] args) throws IOException {
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses("192.168.172.39:11211"));
MemcachedClient client = builder.build();
try {
client.set("hello", 0, 1);
System.out.println("获取设置的内容 = "+client.get("hello"));
GetsResponse<Integer> result = client.gets("hello");
long cas = result.getCas(); //获取当前cas
System.out.println("当前cas = "+cas);
//尝试更新hello成2
if (!client.cas("hello", 0, 2, cas)){
System.err.println("cas error");
}
} catch (TimeoutException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (MemcachedException e) {
e.printStackTrace();
}
}
最开始我的是memecached1.2.1,xmemcached2.0.0。运行main方法后报错,如下:
net.rubyeye.xmemcached.exception.MemcachedException: net.rubyeye.xmemcached.exception.UnknownCommandException: Response error,error message:Unknow command GETS_ONE,key=hello
at net.rubyeye.xmemcached.XMemcachedClient.checkException(XMemcachedClient.java:1921)
at net.rubyeye.xmemcached.XMemcachedClient.fetch0(XMemcachedClient.java:646)
at net.rubyeye.xmemcached.XMemcachedClient.get0(XMemcachedClient.java:1058)
at net.rubyeye.xmemcached.XMemcachedClient.gets(XMemcachedClient.java:1071)
at net.rubyeye.xmemcached.XMemcachedClient.gets(XMemcachedClient.java:1093)
at net.rubyeye.xmemcached.XMemcachedClient.gets(XMemcachedClient.java:1082)
at com.zl.cache.city.CaseTest.main(CaseTest.java:22)
Caused by: net.rubyeye.xmemcached.exception.UnknownCommandException: Response error,error message:Unknow command GETS_ONE,key=hello
at net.rubyeye.xmemcached.command.Command.decodeError(Command.java:251)
at net.rubyeye.xmemcached.command.Command.decodeError(Command.java:279)
at net.rubyeye.xmemcached.command.text.TextGetCommand.decode(TextGetCommand.java:127)
at net.rubyeye.xmemcached.codec.MemcachedDecoder.decode0(MemcachedDecoder.java:61)
at net.rubyeye.xmemcached.codec.MemcachedDecoder.decode(MemcachedDecoder.java:56)
at com.google.code.yanf4j.nio.impl.NioTCPSession.decode(NioTCPSession.java:297)
at com.google.code.yanf4j.nio.impl.NioTCPSession.decodeAndDispatch(NioTCPSession.java:237)
at com.google.code.yanf4j.nio.impl.NioTCPSession.readFromBuffer(NioTCPSession.java:207)
at com.google.code.yanf4j.nio.impl.AbstractNioSession.onRead(AbstractNioSession.java:196)
at com.google.code.yanf4j.nio.impl.AbstractNioSession.onEvent(AbstractNioSession.java:341)
at com.google.code.yanf4j.nio.impl.SocketChannelController.dispatchReadEvent(SocketChannelController.java:56)
at com.google.code.yanf4j.nio.impl.NioController.onRead(NioController.java:157)
at com.google.code.yanf4j.nio.impl.Reactor.dispatchEvent(Reactor.java:323)
at com.google.code.yanf4j.nio.impl.Reactor.run(Reactor.java:180)
错误的意思就是说 gets()方法调用是 无效的命令。如是网上查了一大堆就是没有解释这个错误是如何产生的,也没有说如何解决,可能是我搜索的方法不对,这个问题卡了好久,后来实在想不到就找了另外一台装有memcached的测试机测试,一下子通过了,如是把自己本机的memcached卸载掉重新把测试机上的版本拿过来装一遍,之后在测试也通过的,最后的问题症结在于:[color=red]当xmemcached版本是比较新的时候,memecached的版本也必须升级,必须是在memecached1.2.1以上的版本,新版的xmemcached在实现上有所改动,目前本地上我的是memecached1.4.4-14,xmemcached2.0.0[/color]