close

先簡單介紹一下memcached,之後還會有其它文章陸續的來好好的探討


memcached 位置: http://memcached.org/

目前只提供source抓取,自己要在編釋執行

網路上已經有許多幫忙編譯好的,可以Google一下 'memcached 64 exe' 應該很容易就可以找到了

 

安裝及測試方式

 Step1 : 執行 memcached.exe

 Step2:  選擇並下載 memcached client

              http://code.google.com/p/memcached/wiki/Clients

              我這邊選擇http://www.whalin.com/memcached 來使用

Step3: 測試


public class memcacheTest {import com.meetup.memcached.MemcachedClient;

import com.meetup.memcached.SockIOPool;

protected static MemcachedClient mcc = new MemcachedClient();

static {
SockIOPool pool = SockIOPool.getInstance();
String[] servers = { "127.0.0.1:11211" };
pool.setServers(servers);
pool.setFailover(true);
pool.setInitConn(10);
pool.setMinConn(5);
pool.setMaxConn(250);
pool.setMaintSleep(30);
pool.setNagle(false);
pool.setSocketTO(3000);
pool.setAliveCheck(true);
pool.initialize();
}

public static void test() {

for (int i = 0; i < 1000; i++) {
mcc.set("test" + i, "this is test" + i + " value");
}

for (int i = 0; i < 500; i++) {
mcc.delete("test" + i);
}
System.out.println("***********************");
for (int i = 0; i < 1000; i++) {
System.out.println("[test" + i + "]:" + mcc.get("test" + i));
}
for (int i = 0; i < 500; i++) {
mcc.set("test" + i, "this is test" + i + " value");
}
System.out.println("***********************");
for (int i = 0; i < 1000; i++) {
System.out.println("[test" + i + "]:" + mcc.get("test" + i));
}

for (int i = 0; i < 500; i++) {
mcc.replace("test" + i, "this is test" + i + " value2");
}
System.out.println("***********************");
for (int i = 0; i < 1000; i++) {
System.out.println("[test" + i + "]:" + mcc.get("test" + i));
}
}

/**
* @param args
*/
public static void main(String[] args) {
memcacheTest.test();

}

}

全站熱搜
創作者介紹
創作者 熊爸天下 的頭像
熊爸天下

熊爸天下程式筆記 | 音樂分享

熊爸天下 發表在 痞客邦 留言(0) 人氣()