memcached的java客户端_Memcached Java客户端
代碼示例:
import com.danga.MemCached.*;
import org.apache.log4j.*;
public class TestMemcached {
public static void main(String[] args) {
/*初始化SockIOPool,管理memcached的連接池*/
String[] servers = { "192.168.1.20:12111" };
SockIOPool pool = SockIOPool.getInstance();
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();
/*建立MemcachedClient實(shí)例*/
MemCachedClient memCachedClient = new MemCachedClient();
for (int i = 0; i < 10; i++) {
/*將對象加入到memcached緩存*/
boolean success = memCachedClient.set("" + i, "Hello!");
/*從memcached緩存中按key值取對象*/
String result = (String) memCachedClient.get("" + i);
System.out.println(String.format("set( %d ): %s", i, success));
System.out.println(String.format("get( %d ): %s", i, result));
}
}
}
總結(jié)
以上是生活随笔為你收集整理的memcached的java客户端_Memcached Java客户端的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win10软件拒绝访问删不掉_Win10
- 下一篇: coap python3_node-co