Xmemcached是基于java nio实现的高性能可扩展的memcached客户端。
pom.xml
spring配置
具体使用
memcached服务安装自行参照官网相关文档
pom.xml
<dependency>
<groupId>com.googlecode.xmemcached</groupId>
<artifactId>xmemcached</artifactId>
</dependency>
spring配置
<bean name="memcachedClient" destroy-method="shutdown"
class="net.rubyeye.xmemcached.utils.XMemcachedClientFactoryBean">
<property name="servers">
<value>${memcache.cluster}</value>
</property>
<property name="weights">
<list>
<value>1</value>
<value>2</value>
</list>
</property>
<property name="sessionLocator">
<bean class="net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator" />
</property>
<property name="transcoder">
<bean class="net.rubyeye.xmemcached.transcoders.SerializingTranscoder" />
</property>
<property name="bufferAllocator">
<bean class="net.rubyeye.xmemcached.buffer.SimpleBufferAllocator"/>
</property>
</bean>
具体使用
String key='demo';
String obj='123';
int second=120;
MemcachedClient client=((MemcachedClient)SpringBeanUtil.getBean("memcachedClient"));
client.delete(key);
client.add(key, second, obj);
memcached服务安装自行参照官网相关文档