zoukankan      html  css  js  c++  java
  • Memcached学习(三)

    通过Java客户端实现与Memcached的交互,Java客户端的实现了使用了开源的Memcached-Java-Client,开源地址在GitHub上。

    如下是通过该开源库实现的Memcached交互demo。

     1 import com.schooner.MemCached.SchoonerSockIOPool;
     2 import com.whalin.MemCached.MemCachedClient;
     3 import com.whalin.MemCached.SockIOPool;
     4 
     5 public class TestMem {
     6     
     7     private MemCachedClient mClient;
     8     
     9     public static void main(String[] arg) {
    10         TestMem testMem = new TestMem();
    11         testMem.test();
    12     }
    13     
    14     public TestMem() {
    15         String[] servers ={"127.0.0.1:11211", "127.0.0.1:11212", "127.0.0.1:11213", "127.0.0.1:11214"};
    16         SockIOPool pool = SockIOPool.getInstance();
    17         pool.setServers(servers);
    18         pool.setFailover(true);
    19         pool.setInitConn(5);
    20         pool.setMinConn(2);
    21         pool.setMaxConn(10);
    22         pool.setMaintSleep(30);
    23         pool.setNagle(false);
    24         pool.setSocketTO(3000);
    25         pool.setAliveCheck(true);
    26         pool.setHashingAlg(SchoonerSockIOPool.CONSISTENT_HASH);
    27         pool.initialize();
    28         
    29         mClient = new MemCachedClient(true);
    30     }
    31     
    32     public void test() {
    33         boolean isSucc = false;
    34         isSucc = mClient.set("mKey", "mValue");
    35         log("isSucc:" + isSucc);
    36 
    37         log("obj:" + mClient.get("mKey"));
    38     }
    39     
    40     public static void log(Object obj) {
    41         System.out.println(obj);
    42     }
    43 }
  • 相关阅读:
    ajax 函数外调用
    a连接 h5点击有背景阴影
    禁止微信上下滑动
    ios 倒计时 不动 例如 2017-09-06 00:24:35
    6-10位 a-z || A-Z ||0-9 正则
    正则 不能输入中文
    正整数正则 (选择商品数量)
    手机号正则
    input输入框只能输入数字而且开头不能为零
    do...while02
  • 原文地址:https://www.cnblogs.com/jadic/p/3679800.html
Copyright © 2011-2022 走看看