XMemcached与Spring
来源:互联网 发布:mac上怎么截图 编辑:程序博客网 时间:2024/05/20 07:33
/**
* @Title: SpringXmemcachedTest.java
* @author linhz
* @date 2014-8-22 下午04:56:14
* @version ITPUB1.0
*/
import static junit.framework.Assert.*;
import java.util.concurrent.TimeoutException;
import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.exception.MemcachedException;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
*
* @ClassName: SpringXmemcachedTest
* @Description: TODO(这里用一句话描述这个类的作用)
* @author linhz
* @date 2014-8-22 下午04:56:14
*
*/
public class SpringXmemcachedTest {
private ApplicationContext app;
private MemcachedClient xmemcachedClient;
@Before
public void init() {
app = new ClassPathXmlApplicationContext("spring-xmemcached.xml");
xmemcachedClient = (MemcachedClient) app.getBean("xmemcachedClient");
}
@Test
public void test() {
try {
// 设置/获取
xmemcachedClient.set("philip", 36000, "set/get");
assertEquals("set/get", xmemcachedClient.get("philip"));
// 替换
xmemcachedClient.replace("philip", 36000, "replace");
assertEquals("replace", xmemcachedClient.get("philip"));
// 移除
xmemcachedClient.delete("philip");
assertNull(xmemcachedClient.get("philip"));
} catch (TimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MemcachedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
* @Title: SpringXmemcachedTest.java
* @author linhz
* @date 2014-8-22 下午04:56:14
* @version ITPUB1.0
*/
import static junit.framework.Assert.*;
import java.util.concurrent.TimeoutException;
import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.exception.MemcachedException;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
*
* @ClassName: SpringXmemcachedTest
* @Description: TODO(这里用一句话描述这个类的作用)
* @author linhz
* @date 2014-8-22 下午04:56:14
*
*/
public class SpringXmemcachedTest {
private ApplicationContext app;
private MemcachedClient xmemcachedClient;
@Before
public void init() {
app = new ClassPathXmlApplicationContext("spring-xmemcached.xml");
xmemcachedClient = (MemcachedClient) app.getBean("xmemcachedClient");
}
@Test
public void test() {
try {
// 设置/获取
xmemcachedClient.set("philip", 36000, "set/get");
assertEquals("set/get", xmemcachedClient.get("philip"));
// 替换
xmemcachedClient.replace("philip", 36000, "replace");
assertEquals("replace", xmemcachedClient.get("philip"));
// 移除
xmemcachedClient.delete("philip");
assertNull(xmemcachedClient.get("philip"));
} catch (TimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MemcachedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
spring-xmemcached.xml:
<?xml version="1.0" encoding= "UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- http://code.google.com/p/xmemcached/wiki/Spring_Integration -->
<bean id= "propertyConfigurer1"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name="locations" >
<list>
<value> classpath:xmemcached.properties</value >
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
<bean id= "memcachedClientBuilder" class="net.rubyeye.xmemcached.XMemcachedClientBuilder"
p:connectionPoolSize="${memcached.connectionPoolSize}" p:failureMode="${memcached.failureMode}" >
<!--
XMemcachedClientBuilder have two arguments.First is server list,and
second is weights array.
-->
<constructor-arg>
<list>
<bean class="java.net.InetSocketAddress" >
<constructor-arg>
<value> ${memcached.server1.host}</value >
</constructor-arg>
<constructor-arg>
<value> ${memcached.server1.port}</value >
</constructor-arg>
</bean>
<bean class="java.net.InetSocketAddress" >
<constructor-arg>
<value> ${memcached.server2.host}</value >
</constructor-arg>
<constructor-arg>
<value> ${memcached.server2.port}</value >
</constructor-arg>
</bean>
</list>
</constructor-arg>
<constructor-arg>
<list>
<value> ${memcached.server1.weight}</value >
<value> ${memcached.server2.weight}</value >
</list>
</constructor-arg>
<property name="commandFactory" >
<bean class="net.rubyeye.xmemcached.command.TextCommandFactory" />
</property>
<property name="sessionLocator" >
<bean class="net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator" />
</property>
<property name="transcoder" >
<bean class="net.rubyeye.xmemcached.transcoders.SerializingTranscoder" />
</property>
</bean>
<!-- Use factory bean to build memcached client -->
<bean id= "xmemcachedClient" factory-bean ="memcachedClientBuilder"
factory-method="build" destroy-method= "shutdown" />
</beans>
xmemcached.properties:
memcached.connectionPoolSize=50
memcached.failureMode=true
#server1
memcached.server1.host=132.96.27.25
memcached.server1.port=11211
memcached.server1.weight=1
#server2
memcached.server2.host=132.96.27.25
memcached.server2.port=11212
memcached.server2.weight=1
0 0
- XMemcached与Spring
- XMemcached与Spring集成
- Spring与Memcached-xmemcached整合
- Memcached xmemcached与 Spring集成
- xmemcached使用之与spring整合
- xmemcached使用之与spring整合
- Xmemcached使用之与Spring整合
- Xmemcached使用之与Spring整合
- Xmemcached与Spring 3.0的集成
- Xmemcached与Spring 3.0的集成
- 使用memcached客户端Xmemcached与Spring整合
- Xmemcached使用之与Spring整合
- XMemcached与spring的集成实例
- xmemcached主要用法及与Spring集成--总结
- memcached-java客户端xmemcached使用总结 & 与Spring 集成
- xmemcached主要用法及与Spring集成--总结
- xmemcached主要用法及与Spring集成--总结
- XMemcached&Spring集成
- UVA - 1485 Permutation Counting
- OJ问题检测程序---python开发
- The Triangle
- jsp include html 乱码问题 <%@ include page=""%>
- 标准化与标准计分
- XMemcached与Spring
- 【2892】A SDUTOJ
- android jni javah自动生成头文件
- GIT 开始一次旅行 三 ( 建立一个github 远程 仓库)
- crossApp部署到Eclipse
- 学习之精华
- poj2240 Arbitrage
- 2dx-Box2d
- JSON学习笔记1