Memcache与Spring集成实例
来源:互联网 发布:mac 显示器 缩放 编辑:程序博客网 时间:2024/06/11 23:48
学习了memcache,这是个好东西,分享一下自己的小实例,也方便以后查找使用
一、前期准备
1) 下载memcached服务端memcached-1.2.6-win32-bin.zip,地址:http://code.jellycan.com/memcached/
2) 下载java版客户端 java_memcached-release_2.6.1.zip
3) 解压缩memcached-1.2.6-win32-bin.zip到指定目录,例如:D:\memcached-1.2.6-win32 ,在终端(即cmd命令行界面)
D:\memcached-1.2.6-win32\memcached.exe -d install
D:\memcached\memcached.exe -d start
这样memcache就会作为windows系统服务在每次开机时启动memcache服务。
常用命令
-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 显示帮助
二、实例代码
memcache.properties memcache的连接属性 这是本机做服务器的,如果是其它机器,换ip 端口即可
测试类
一、前期准备
1) 下载memcached服务端memcached-1.2.6-win32-bin.zip,地址:http://code.jellycan.com/memcached/
2) 下载java版客户端 java_memcached-release_2.6.1.zip
3) 解压缩memcached-1.2.6-win32-bin.zip到指定目录,例如:D:\memcached-1.2.6-win32 ,在终端(即cmd命令行界面)
D:\memcached-1.2.6-win32\memcached.exe -d install
D:\memcached\memcached.exe -d start
这样memcache就会作为windows系统服务在每次开机时启动memcache服务。
常用命令
-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 显示帮助
二、实例代码
spring-memcache.xml 配置pool和memcache客户端
<?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.properties memcache的连接属性 这是本机做服务器的,如果是其它机器,换ip 端口即可
memcache.server=127.0.0.1:11211memcache.initConn=20memcache.minConn=10memcache.maxConn=50memcache.maintSleep=3000memcache.nagle=falsememcache.socketTO=3000
测试类
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")); } }
- memcache与spring集成 实例
- Memcache与Spring集成实例
- memcache与spring集成 实例
- memcache与spring集成
- spring与memcache的集成
- spring缓存集成memcache
- spring缓存集成memcache
- spring缓存集成memcache
- spring缓存集成memcache
- Memcache Spring集成
- Struts2 与 Spring 集成实例
- Struts2 与 Spring 集成实例
- Spring与Quartz集成实例
- 搭建JAVAEE Memcache 集群环境之与Spring集成(四)
- spring+memcache实践实例
- spring集成memcache 示例一
- spring集成memcache 示例二
- spring集成memcache 示例一
- CISCO实验模拟器完全攻略
- FatFs中文介绍和移植方法(转载)
- Visual Assist X V10.7.1929.0 官方原版+破解补丁+破解方法
- 编码规范
- UITextField 与 键盘
- Memcache与Spring集成实例
- Xcode中断点的威力
- Miyeok Guk (Korean Seaweed Soup) - Миён Гук (Корейский суп из морепродуктов)
- PlSql安装报错 plsql some oracle net versions cannot connect from a path
- 键盘
- ios开发入门到精通教程-传智播客ios培训学院
- C++标准转换运算符reinterpret_cast
- Ext JS4百强应用: 做可编辑的,可checked的treegrid--第11强
- linux关于文件分配置权限