學習了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服務。
-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



















































測試類:
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"));
}
}