Package net.rubyeye.xmemcached

Examples of net.rubyeye.xmemcached.MemcachedClient


    validateClient(memcachedClient);
  }

  public void testAllConfig() throws Exception {
    MemcachedClient memcachedClient = (MemcachedClient) this.ctx
        .getBean("memcachedClient2");
    validateClient(memcachedClient);
  }
View Full Code Here


        .getBean("memcachedClient2");
    validateClient(memcachedClient);
  }

  public void testComposite() throws Exception {
    MemcachedClient memcachedClient1 = (MemcachedClient) this.ctx
        .getBean("memcachedClient1");
    MemcachedClient memcachedClient2 = (MemcachedClient) this.ctx
        .getBean("memcachedClient2");
    validateClient(memcachedClient1);
    memcachedClient1.flushAll();
    validateClient(memcachedClient2);
  }
View Full Code Here

    builder.setSessionLocator(getSessionLocator());
    builder.getConfiguration()
        .setSessionReadBufferSize(getReadBufferSize());
    builder.setConnectionPoolSize(getConnectionPoolSize());
    builder.setConnectTimeout(getConnectTimeoutMillis());
    MemcachedClient client = builder.build();
    client.setOpTimeout(getOperationTimeoutMillis());
    return new Xmemcache(client);
  }
View Full Code Here

  public static void main(String[] args) {
    if (args.length < 1) {
      System.err.println("Useage:java SimpleExample [servers]");
      System.exit(1);
    }
    MemcachedClient memcachedClient = getMemcachedClient(args[0]);
    if (memcachedClient == null) {
      throw new NullPointerException(
          "Null MemcachedClient,please check memcached has been started");
    }
    try {
      // add a,b,c
      System.out.println("Add a,b,c");
      memcachedClient.set("a", 0, "Hello,xmemcached");
      memcachedClient.set("b", 0, "Hello,xmemcached");
      memcachedClient.set("c", 0, "Hello,xmemcached");
      // get a
      String value = memcachedClient.get("a");
      System.out.println("get a=" + value);
      System.out.println("delete a");
      // delete a
      memcachedClient.delete("a");
      // reget a
      value = memcachedClient.get("a");
      System.out.println("after delete,a=" + value);

      System.out.println("Iterate all keys...");
      // iterate all keys
      KeyIterator it = memcachedClient.getKeyIterator(AddrUtil
          .getOneAddress(args[0]));
      while (it.hasNext()) {
        System.out.println(it.next());
      }
      System.out.println(memcachedClient.touch("b", 1000));

    } catch (MemcachedException e) {
      System.err.println("MemcachedClient operation fail");
      e.printStackTrace();
    } catch (TimeoutException e) {
      System.err.println("MemcachedClient operation timeout");
      e.printStackTrace();
    } catch (InterruptedException e) {
      // ignore
    }
    try {
      memcachedClient.shutdown();
    } catch (Exception e) {
      System.err.println("Shutdown MemcachedClient fail");
      e.printStackTrace();
    }
  }
View Full Code Here

    if (args.length < 1) {
      System.err
          .println("Useage:java MemcachedStateListenerExample [servers]");
      System.exit(1);
    }
    MemcachedClient memcachedClient = getMemcachedClient(args[0]);
    try {
      memcachedClient.shutdown();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
View Full Code Here

    int NUM = Integer.parseInt(args[0]);
    MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil
        .getAddresses(args[1]));
    // use binary protocol
    builder.setCommandFactory(new BinaryCommandFactory());
    MemcachedClient mc = builder.build();
    // initial value is 0
    mc.set("a", 0, 0);
    CountDownLatch cdl = new CountDownLatch(NUM * 100);
    long start = System.currentTimeMillis();
    // start Num threads to increase 'a'
    for (int i = 0; i < NUM; i++) {
      new CASThread(mc, cdl).start();
    }

    cdl.await();
    System.out.println("test cas,timed:"
        + (System.currentTimeMillis() - start));
    // print result,must equals to NUM
    System.out.println("result=" + mc.get("a"));
    mc.shutdown();
  }
View Full Code Here

    if (args.length < 3) {
      System.err
          .println("Useage:java SASLExample servers username password");
      System.exit(1);
    }
    MemcachedClient memcachedClient = getMemcachedClient(args[0], args[1],
        args[2]);
    if (memcachedClient == null) {
      throw new NullPointerException(
          "Null MemcachedClient,please check memcached has been started");
    }
    try {
      // add a
      System.out.println("Add a,b,c");
      memcachedClient.set("a", 0, "Hello,xmemcached");
      // get a
      String value = memcachedClient.get("a");
      System.out.println("get a=" + value);
      System.out.println("delete a");
      // delete a
      memcachedClient.delete("a");
      value = memcachedClient.get("a");
      System.out.println("after delete,a=" + value);
    } catch (MemcachedException e) {
      System.err.println("MemcachedClient operation fail");
      e.printStackTrace();
    } catch (TimeoutException e) {
      System.err.println("MemcachedClient operation timeout");
      e.printStackTrace();
    } catch (InterruptedException e) {
      // ignore
    }
    try {
      memcachedClient.shutdown();
    } catch (Exception e) {
      System.err.println("Shutdown MemcachedClient fail");
      e.printStackTrace();
    }
  }
View Full Code Here

    final AtomicInteger failure = new AtomicInteger();
    final AtomicInteger success = new AtomicInteger();
    MemcachedClientBuilder builder = new XMemcachedClientBuilder(
        AddrUtil.getAddresses(servers));
    //builder.setCommandFactory(new BinaryCommandFactory());
    MemcachedClient client = builder.build();
    ClockWatch watch = new ClockWatch();
    CyclicBarrier barrier = new CyclicBarrier(threads + 1, watch);
    for (int i = 0; i < threads; i++) {
      new TestThread(repeat, i * repeat * 2, size, client, failure,
          success, barrier).start();
    }
    new Thread() {
      public void run() {
        try {
          while (success.get() + failure.get() < repeat * threads) {
            Thread.sleep(1000);
            System.out.println("success:" + success.get()
                + ",failure:" + failure.get());
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }.start();
    watch.start();
    barrier.await();
    barrier.await();

    long secs = watch.getDurationInMillis() / 1000;
    int total = 4 * repeat * threads;
    long tps = total / secs;
    client.shutdown();
    System.out.println("duration:" + secs + " seconds,tps:" + tps
        + " op/seconds,total:" + total + " ops");

  }
View Full Code Here

  public static void main(String[] args) {
    if (args.length < 1) {
      System.err.println("Useage:java BinaryProtocolExample [servers]");
      System.exit(1);
    }
    MemcachedClient memcachedClient = getMemcachedClient(args[0]);
    if (memcachedClient == null) {
      throw new NullPointerException(
          "Null MemcachedClient,please check memcached has been started");
    }
    try {
      // add a
      System.out.println("Add a,b,c");
      memcachedClient.set("a", 0, "Hello,xmemcached");
      // get a
      String value = memcachedClient.get("a");
      System.out.println("get a=" + value);
      System.out.println("delete a");
      // delete a
      memcachedClient.delete("a");
      value = memcachedClient.get("a");
      System.out.println("after delete,a=" + value);
    } catch (MemcachedException e) {
      System.err.println("MemcachedClient operation fail");
      e.printStackTrace();
    } catch (TimeoutException e) {
      System.err.println("MemcachedClient operation timeout");
      e.printStackTrace();
    } catch (InterruptedException e) {
      // ignore
    }
    try {
      memcachedClient.shutdown();
    } catch (Exception e) {
      System.err.println("Shutdown MemcachedClient fail");
      e.printStackTrace();
    }
  }
View Full Code Here

    builder.setConnectionPoolSize(connCount);
    if (useBinaryProtocl) {
      builder.setCommandFactory(new BinaryCommandFactory());
    }

    MemcachedClient memcachedClient = builder.build();
    System.out.println("Xmemcached startup");
    warmUp(memcachedClient);

    for (int i = 0; i < THREADS.length; i++) {
      for (int j = 0; j < BYTES.length; j++) {
        int repeats = getReapts(i);
        test(memcachedClient, BYTES[j], THREADS[i], repeats, true);
      }
    }
    memcachedClient.shutdown();

  }
View Full Code Here

TOP

Related Classes of net.rubyeye.xmemcached.MemcachedClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.