Examples of MemcachedClient


Examples of net.rubyeye.xmemcached.MemcachedClient

        .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

Examples of net.rubyeye.xmemcached.MemcachedClient

    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

Examples of net.rubyeye.xmemcached.MemcachedClient

  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

Examples of net.rubyeye.xmemcached.MemcachedClient

    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

Examples of net.rubyeye.xmemcached.MemcachedClient

    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

Examples of net.rubyeye.xmemcached.MemcachedClient

    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

Examples of net.spy.memcached.MemcachedClient

    private MemcachedClient client;

    MemcachedCache(String hostname, int port) {
        try {
            this.client = new MemcachedClient(new InetSocketAddress(hostname, port));
        } catch (IOException e) {
            throw new RuntimeException("Unable to create a Memcached client", e);
        }
    }
View Full Code Here

Examples of net.spy.memcached.MemcachedClient

     * machine as your application, for example.
     * @param address where the <i>memcached</i> daemon is running
     * @throws IOException in case of an error
     */
    public MemcachedHttpCacheStorage(InetSocketAddress address) throws IOException {
        this(new MemcachedClient(address));
    }
View Full Code Here

Examples of net.spy.memcached.MemcachedClient

   *
   * @param addresses
   * @throws IOException
   */
  public Memcached(String addresses) throws IOException {   
    client = new MemcachedClient(new PwaBinaryConnectionFactory(), AddrUtil.getAddresses(addresses));   
                //AddrUtil.getAddresses("server1:11211 server2:11211"));           
      System.out.println("Connected to servers at "+addresses);
  }
View Full Code Here

Examples of net.spy.memcached.MemcachedClient

      String[] hostPort = hostname.split(":");
      addresses.add(new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1])));
    }
   
    try {
      this.client = new MemcachedClient(addresses);
    } catch (final IOException e) {
      throw new IllegalStateException(e);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.