spring与memcached整合

Software is like sex,it is better when it is free.
spring整合memcached

下载windows下的memcached,安装运行步骤:

1、安装 c:\memcached\memcached.exe -d install

2、启动 c:\memcached\memcached.exe -d start

memcached的基本设置:

-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 applicationContext.xml中设置

1. <bean id="memcache" class="com.danga.MemCached.SockIOPool"
2. factory-method="getInstance" init-method="initialize"
3. destroy-method="shutDown">
4. <constructor-arg>
5. <value>memcache</value>
6. </constructor-arg>
7. <property name="servers">
8. <list>
9. <value>${memcache.server}</value>
10. </list>
11. </property>
12. <property name="initConn">
13. <value>${memcache.initConn}</value>
14. </property>
15. <property name="minConn">
16. <value>${memcache.minConn}</value>
17. </property>
18. <property name="maxConn">
19. <value>${memcache.maxConn}</value>
20. </property>
21. <property name="maintSleep">
22. <value>${memcache.maintSleep}</value>
23. </property>
24. <property name="nagle">
25. <value>${memcache.nagle}</value>
26. </property>
27. <property name="socketTO">
28. <value>${memcache.socketTO}</value>
29. </property>
30. </bean>

配置信息
memcache.server=192.168.0.9:11211
memcache.initConn=20
memcache.minConn=10
memcache.maxConn=50
memcache.maintSleep=30
memcache.nagle=false
memcache.socketTO=3000
memcached常用方法:
1、设置数据到内存
memCachedClient.set(key, value, cache中存在时长);
2、删除内存中的数据
memCachedClient.delete(key);
3、取得内存中的数据
memCachedClient.get(key);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值