1、在pom文件中加入xmemcached的依赖
class="java">
<dependency>
<groupId>com.googlecode.xmemcached</groupId>
<artifactId>xmemcached</artifactId>
<version>1.3.8</version>
</dependency>
2、在java代码中使用xmemcached,代码如下
import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.MemcachedClientBuilder;
import net.rubyeye.xmemcached.XMemcachedClientBuilder;
import net.rubyeye.xmemcached.utils.AddrUtil;
import org.junit.Test;
public class MemcacheStudy {
@Test
public void memcachedWithoutSpring() throws Exception{
//初始化memcached服务器信息
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses("localhost:11211"));
MemcachedClient client = builder.build();
//使用clint来进行存储
client.set("hello", 0, "hello Xmemcached!");
//使用client来进行查询
String value = client.get("hello");
System.out.println(value);
//关闭client
client.shutdown();
}
}