Memecached实现缓存系统搭建。

xiaoxiao2026-06-06  12

1.在windows系统或Linux系统上安装memecached的服务器端。 2.java客户端的调用代码 import com.danga.MemCached.MemCachedClient;import com.danga.MemCached.SockIOPool;public class MemoCache { private static final String POOL_NAME = "Memo_Pool"; public static MemCachedClient mcc; static { // 设置缓存服务器列表,当使用分布式缓存的时,可以指定多个缓存服务器 String[] servers = { "11.177.50.36:11211" }; // 与服务器列表中对应的各服务器的权重 Integer[] weights = { 3 }; // 创建Socked连接池 SockIOPool pool = SockIOPool.getInstance(POOL_NAME); // 向连接池设定服务器和权重 pool.setServers(servers); pool.setWeights(weights); // 连接池参数 pool.setInitConn(5); pool.setMinConn(5); pool.setMaxConn(250); pool.setMaxIdle(1000 * 60 * 60 * 6); // set the sleep for the maint thread // it will wake up every x seconds and // maintain the pool size pool.setMaintSleep(30); // set some TCP settings // disable nagle // set the read timeout to 3 secs // and don't set a connect timeout pool.setNagle(false); pool.setSocketTO(3000); pool.setSocketConnectTO(0); // initialize the connection pool pool.initialize(); // lets set some compression on for the client // compress anything larger than 64k mcc = new MemCachedClient(POOL_NAME); mcc.setCompressEnable(true); mcc.setCompressThreshold(64 * 1024); } public static void main(String[] args) throws Exception { // mcc.set("msg", "This is a test String"); // mcc.set("msg", "Hello,world!", new Date( // System.currentTimeMillis() + 1300)); System.out.println(MemoCache.mcc.get("msg")); }} 参考: http://www.danga.com/memcached/ http://www.infoq.com/cn/articles/memcached-java http://jehiah.cz/projects/memcached-win32/ http://www.ccvita.com/258.html http://tech.idv2.com/2008/07/10/memcached-001/ http://www.91linux.com/html/article/program/java/20090207/15708.html
转载请注明原文地址: https://www.6miu.com/read-5049678.html

最新回复(0)