少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(22)

          我參與的團(tuán)隊(duì)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          學(xué)習(xí)了memcache,這是個(gè)好東西,分享一下自己的小實(shí)例,也方便以后查找使用

          一、前期準(zhǔn)備

          1)  下載memcached服務(wù)端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就會(huì)作為windows系統(tǒng)服務(wù)在每次開機(jī)時(shí)啟動(dòng)memcache服務(wù)。
           
          常用命令
           
          -p 監(jiān)聽的端口 
          -l 連接的IP地址, 默認(rèn)是本機(jī) 
          -d start 啟動(dòng)memcached服務(wù) 
          -d restart 重起memcached服務(wù) 
          -d stop|shutdown 關(guān)閉正在運(yùn)行的memcached服務(wù) 
          -d install 安裝memcached服務(wù) 
          -d uninstall 卸載memcached服務(wù) 
          -u 以的身份運(yùn)行 (僅在以root運(yùn)行的時(shí)候有效) 
          -m 最大內(nèi)存使用,單位MB。默認(rèn)64MB 
          -M 內(nèi)存耗盡時(shí)返回錯(cuò)誤,而不是刪除項(xiàng) 
          -c 最大同時(shí)連接數(shù),默認(rèn)是1024 
          -f 塊大小增長因子,默認(rèn)是1.25 
          -n 最小分配空間,key+value+flags默認(rèn)是48 
          -h 顯示幫助 



          spring-memcache.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:aop="http://www.springframework.org/schema/aop"
              xmlns:cache
          ="http://www.springframework.org/schema/cache"
              xmlns:context
          ="http://www.springframework.org/schema/context"
              xmlns:mvc
          ="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
              xmlns:p
          ="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
              xsi:schemaLocation
          ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
              http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  
              http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd  
                 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                 http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">

              
          <bean id="memcachedPool" class="com.danga.MemCached.SockIOPool"
                  factory
          -method="getInstance" init-method="initialize" destroy-method="shutDown">
                  
          <constructor-arg>
                      
          <value>neeaMemcachedPool</value>
                  
          </constructor-arg>
                  
          <property name="servers">
                      
          <list>
                          
          <value>127.0.0.1:11211</value>
                      
          </list>
                  
          </property>
                  
          <property name="initConn">
                      
          <value>20</value>
                  
          </property>
                  
          <property name="minConn">
                      
          <value>10</value>
                  
          </property>
                  
          <property name="maxConn">
                      
          <value>50</value>
                  
          </property>
                  
          <property name="maintSleep">
                      
          <value>3000</value>
                  
          </property>
                  
          <property name="nagle">
                      
          <value>false</value>
                  
          </property>
                  
          <property name="socketTO">
                      
          <value>3000</value>
                  
          </property>
              
          </bean>
              
              
          <bean id="memcachedClient" class="com.danga.MemCached.MemCachedClient">
                  
          <constructor-arg>
                      
          <value>neeaMemcachedPool</value>
                  
          </constructor-arg>
              
          </bean>
              

          </beans>






          測試類:

          package com.abin.lee.spring.memcache;

          import org.junit.BeforeClass;
          import org.junit.Test;
          import org.springframework.context.ApplicationContext;
          import org.springframework.context.support.ClassPathXmlApplicationContext;

          import com.danga.MemCached.MemCachedClient;

          public class MemcacheUtilTest {
           static MemCachedClient memcachedClient;
           @BeforeClass
           public static void setUpBeforeClass() throws Exception {
            ApplicationContext context= new ClassPathXmlApplicationContext("com/abin/lee/spring/memcache/spring-memcache.xml");
            memcachedClient= (MemCachedClient)context.getBean("memcachedClient");
           }

           @Test
           public void test() {
            memcachedClient.set("name", "abin");
            System.out.println(memcachedClient.get("name"));
           }
          }

          posted on 2012-11-10 22:33 abin 閱讀(1356) 評論(1)  編輯  收藏 所屬分類: memcache

          Feedback

          # re: spring memcache 2013-03-04 11:53 http://www.easy518.com/
          http://www.easy518.com/  回復(fù)  更多評論
            

          主站蜘蛛池模板: 嵊泗县| 克山县| 花莲县| 宝丰县| 饶平县| 蛟河市| 广宁县| 凤冈县| 凤庆县| 隆安县| 潍坊市| 石林| 黔江区| 林州市| 景谷| 苍山县| 大安市| 雷波县| 诏安县| 开江县| 景宁| 余姚市| 遵义市| 九龙城区| 尚义县| 莱州市| 泌阳县| 六枝特区| 德令哈市| 溧水县| 靖江市| 台前县| 夏津县| 松阳县| 阿尔山市| 休宁县| 明水县| 长阳| 靖边县| 威海市| 嵊泗县|