xMemcached 的学习
在学习xmemcached,由于没有安装linux环境,所以在windows环境下进行测试,此文章主要记录一些需要的环境,以及出现的异常的处理情况。
环境: 1)memcached for windows: memcached-1.2.1-win32.zip
2) xmemcached-1.3.5-bin-with-dependencies.tar.gz
步骤一:windows下安装memcached 很简单,并启动memcached
步骤二: 参考xMemcached的 User_Guide_zh 采用 eclipse 编写简单的测试用例
开始导入的jar 是: slf4j-api-1.5.6.jar 和xmemcached-1.3.5.jar
写了一个简单的类:
public static void main(String[] args){
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses("127.0.0.1:11211"));
MemcachedClient xMemcachedClient = null;
try {
xMemcachedClient = builder.build();
xMemcachedClient.set("hello", 0, "hello world!");
String value = xMemcachedClient.get("hello");
System.out.println("=========== From memcached value is:"+value);
xMemcachedClient.delete("hello");
value = xMemcachedClient.get("hello");
System.out.println("=========hello===:"+value);
} catch (IOException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (MemcachedException e) {
e.printStackTrace();
}
try {
xMemcachedClient.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
结果运行error:java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
缺少jar 看样子时缺少log 包,我下载了 一个log4j 的包,还是同样的error, 最后下载了一个nlog4j-1.2.25.jar 问题解决,包结构如下图