<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    少年阿賓

    那些青春的歲月

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

    學習了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 顯示幫助 



    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 閱讀(1354) 評論(1)  編輯  收藏 所屬分類: memcache

    Feedback

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

    主站蜘蛛池模板: 免费观看的毛片手机视频| 亚洲高清在线观看| 九九美女网站免费| 91丁香亚洲综合社区| 亚洲第一视频在线观看免费| 毛片在线播放免费观看| 亚洲欧美精品午睡沙发| 国产亚洲综合一区柠檬导航| 久久WWW色情成人免费观看| 一日本道a高清免费播放| 亚洲欧洲日产专区| 亚洲真人日本在线| 国产片AV片永久免费观看| 免费国产在线精品一区| 亚洲人成网站日本片| 国产精品亚洲高清一区二区| 无码日韩精品一区二区免费| 中文字幕无线码免费人妻| 91丁香亚洲综合社区| 亚洲Av无码精品色午夜| 又黄又爽无遮挡免费视频| 91精品国产免费久久久久久青草 | 亚洲国产综合在线| 亚洲中文字幕无码专区| 免费看国产成年无码AV片| 精品一卡2卡三卡4卡免费视频| 国产精品亚洲а∨天堂2021| 亚洲精品电影天堂网| 国产午夜亚洲精品理论片不卡| 好男人视频社区精品免费| 蜜桃成人无码区免费视频网站| a在线视频免费观看在线视频三区 a毛片成人免费全部播放 | 男人j进女人p免费视频| 亚洲人成人网毛片在线播放| 亚洲AV无码一区东京热| 亚洲情侣偷拍精品| 暖暖在线日本免费中文| 青春禁区视频在线观看直播免费| 男女午夜24式免费视频| 999zyz**站免费毛片| www成人免费观看网站|