Memecached实现缓存系统搭建。

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值