Java Connection Couchbase Memcache

Source: Internet
Author: User
Tags couchbase

No reference code when the re-write or a little tired, this is a review, the first time to write a reference to some other messy code, although not with this same, but do not understand the situation is quickly written out, but this is the only need to find what jars have been engaged for half a day, Finally found that the extern with a jar is enough, addresses and Auth before is also confused, this time finally to figure out

Maven Introduction

<Dependency>    <groupId>Com.googlecode.xmemcached</groupId>    <Artifactid>Xmemcached</Artifactid>    <version>1.4.3</version> </Dependency>

First, according to the previous "Remember Couchbase (memcached) installation and use" Steps to install, type selection couchbase on the line,
The test code is as follows:

 Packagetest.test;Importjava.io.IOException;Importjava.util.concurrent.TimeoutException;Importnet.rubyeye.xmemcached.MemcachedClient;ImportNet.rubyeye.xmemcached.MemcachedClientBuilder;ImportNet.rubyeye.xmemcached.XMemcachedClientBuilder;ImportNet.rubyeye.xmemcached.auth.AuthInfo;Importnet.rubyeye.xmemcached.command.BinaryCommandFactory;Importnet.rubyeye.xmemcached.exception.MemcachedException;ImportNet.rubyeye.xmemcached.utils.AddrUtil; Public classApp { Public Static voidMain (string[] args) {Try{Memcachedclientbuilder Builder=NewXmemcachedclientbuilder (addrutil.getaddresses ("192.168.92.128:11211")) ; Builder.addauthinfo (Addrutil.getoneaddress ("192.168.92.128:11211"), Authinfo.plain ("Azul", "XXXX")); Builder.setcommandfactory (Newbinarycommandfactory ()); Builder.setfailuremode (true); Builder.setconnectionpoolsize (10); Memcachedclient Client=Builder.build (); Client.set ("Lwk", 0, "Hello"); String value= Client.get ("Key");            System.out.println (value);        Client.shutdown (); } Catch(IOException e) {e.printstacktrace (); } Catch(TimeoutException e) {e.printstacktrace (); } Catch(interruptedexception e) {e.printstacktrace (); } Catch(memcachedexception e) {e.printstacktrace (); } System.out.println ("End ..." ); }}

Execution Result:

class "Org.slf4j.impl.StaticLoggerBinder". Slf4j:defaulting to no-operation (NOP) Logger implementationslf4j:see http://  Www.slf4j.org/codes.html#StaticLoggerBinder for further details. helloend ...

The admin interface can see:

It's a ciphertext store.

If you don't need SASL verification, remove the validation from the server and write it down.

 Packagetest.test;ImportNet.spy.memcached.AddrUtil;Importnet.spy.memcached.MemcachedClient; Public classApp { Public Static voidMain (string[] args) {Try{memcachedclient Client=NewMemcachedclient (addrutil.getaddresses ("192.168.92.128:11211")); Client.set ("Lwk", 0, "Hello"); Object value= Client.get ("Lwk");            System.out.println (value);        Client.shutdown (); } Catch(Exception e) {e.printstacktrace (); } System.out.println ("End ..." ); }}

Results:

2015-03-01 23:26:38.268 INFO net.spy.memcached.MemcachedConnection:  Added {QA sa=/192.168.92.128:11202, #Rops = 0, #Wops =0, #iq =0, toprop=null, topwop=null, towrite=0, Interested=0} to connect queue 2015-03-01 23:26:38.271 INFO net.spy.memcached.MemcachedConnection: For    [email protected] 2015-03-01 23:26:38.276 WARN net.spy.memcached.MemcachedConnection: For    lwk.helloend ... 2015-03-01 23:26:38.284 INFO net.spy.memcached.MemcachedConnection:  Shut down memcached client

This is accessed through the Java client, and try it out in a moment with the command line.

Java Connection Couchbase Memcache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.