Spring与Memcached整合
2015-11-21 14:53
609 查看
一、前期准备
D:\memcached-1.2.6-win32\memcached.exe -d install
D:\memcached\memcached.exe -d start
-p 监听的端口
-l 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25
-n 最小分配空间,key+value+flags默认是48
-h 显示帮助
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:properties/memcache.properties</value>
</list>
</property>
</bean>
<bean id="memcachedPool" class="com.danga.MemCached.SockIOPool"
factory-method="getInstance" init-method="initialize"
destroy-method="shutDown">
<constructor-arg>
<value>memCachedPool</value>
</constructor-arg>
<property name="servers">
<list>
<value>${memcache.server}</value>
</list>
</property>
<property name="initConn">
<value>${memcache.initConn}</value>
</property>
<property name="minConn">
<value>${memcache.minConn}</value>
</property>
<property name="maxConn">
<value>${memcache.maxConn}</value>
</property>
<property name="maintSleep">
<value>${memcache.maintSleep}</value>
</property>
<property name="nagle">
<value>${memcache.nagle}</value>
</property>
<property name="socketTO">
<value>${memcache.socketTO}</value>
</property>
</bean>
<bean id="memCachedClient" class="com.danga.MemCached.MemCachedClient">
<constructor-arg>
<value>memCachedPool</value>
</constructor-arg>
</bean>
</beans>
memcache.server=127.0.0.1:11211
memcache.initConn=20
memcache.minConn=10
memcache.maxConn=50
memcache.maintSleep=3000
memcache.nagle=false
memcache.socketTO=3000
TestMemcache.java测试类 用的是junit4
[html] view
plaincopy
package com.pis.memcache;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.danga.MemCached.MemCachedClient;
public class TestMemcache {
MemCachedClient memCachedClient;
@Before
public void beforeTest(){
ApplicationContext atx = new ClassPathXmlApplicationContext("/spring/spring-memcache.xml");
memCachedClient = (MemCachedClient)atx.getBean("memCachedClient");
}
@Test
public void TestMem(){
memCachedClient.set("name", "han");
System.out.println(memCachedClient.get("name"));
}
}
1) 下载memcached服务端memcached-1.2.6-win32-bin.zip,地址:http:
//code.jellycan.com/memcached/
D:\memcached-1.2.6-win32\memcached.exe -d install
D:\memcached\memcached.exe -d start
-p 监听的端口
-l 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25
-n 最小分配空间,key+value+flags默认是48
-h 显示帮助
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:properties/memcache.properties</value>
</list>
</property>
</bean>
<bean id="memcachedPool" class="com.danga.MemCached.SockIOPool"
factory-method="getInstance" init-method="initialize"
destroy-method="shutDown">
<constructor-arg>
<value>memCachedPool</value>
</constructor-arg>
<property name="servers">
<list>
<value>${memcache.server}</value>
</list>
</property>
<property name="initConn">
<value>${memcache.initConn}</value>
</property>
<property name="minConn">
<value>${memcache.minConn}</value>
</property>
<property name="maxConn">
<value>${memcache.maxConn}</value>
</property>
<property name="maintSleep">
<value>${memcache.maintSleep}</value>
</property>
<property name="nagle">
<value>${memcache.nagle}</value>
</property>
<property name="socketTO">
<value>${memcache.socketTO}</value>
</property>
</bean>
<bean id="memCachedClient" class="com.danga.MemCached.MemCachedClient">
<constructor-arg>
<value>memCachedPool</value>
</constructor-arg>
</bean>
</beans>
memcache.server=127.0.0.1:11211
memcache.initConn=20
memcache.minConn=10
memcache.maxConn=50
memcache.maintSleep=3000
memcache.nagle=false
memcache.socketTO=3000
TestMemcache.java测试类 用的是junit4
[html] view
plaincopy
package com.pis.memcache;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.danga.MemCached.MemCachedClient;
public class TestMemcache {
MemCachedClient memCachedClient;
@Before
public void beforeTest(){
ApplicationContext atx = new ClassPathXmlApplicationContext("/spring/spring-memcache.xml");
memCachedClient = (MemCachedClient)atx.getBean("memCachedClient");
}
@Test
public void TestMem(){
memCachedClient.set("name", "han");
System.out.println(memCachedClient.get("name"));
}
}
相关文章推荐
- memcached实现tomcat集群的session共享
- Redis和Memcache性能测试对比
- 内存碎片和memcached slab控制碎片方法
- 简单理解Memcached的Slab Allocation
- 剖析Memcached分布式内存对象缓存系统的工作原理
- 网站缓存技术总结( ehcache memcache redis)
- 关于mongodb ,redis,memcache之间见不乱理还乱的关系和作用
- memcached相关
- memcached在windows下的安装与命令使用方法
- 在Linux上安装Memcached服务
- JAVA MemCache 史无前例的详细讲解【转】
- tlinux(CentOS)下memcached 安装与使用
- 为什么不能用memcached存储Session
- memcache(使用telnet操作)
- 阿里云Ubuntu 14.04.2 memcached安装后客户端连接时提示no route to host
- tomcat使用memcached完成集群(session共享实现方式)
- MSM--Memcached_Session_Manager介绍及使用
- Memcached, Redis, MongoDB三者比较
- Window下memcached安装与测试步骤
- LNMP 添加 memcached服务