java代码的简单使用。
import com.danga.MemCached.MemCachedClient;
import com.danga.MemCached.SockIOPool;
public class TestMemcached {
//memcached 服务列表
private static String[] servers = { "127.0.0.1:11211"};
public static void main(String[] args) {
//初始化SockIOPool,管理memcached的连接池
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实例*/
MemCachedClient memCachedClient = new MemCachedClient();
//注意 对于对象需实现 Serializable 接口 或者变成json字符串保存
boolean status = memCachedClient.set("person", "{}");
//从缓存获取
String pp = (String) memCachedClient.get("person");
System.out.println(String.format("保存状态:%s, 从缓存获得的:%s", status, pp));
}
}