1、pom.xml中加入依赖
<dependency> <groupId>com.couchbase.client</groupId> <artifactId>couchbase-client</artifactId> <version>1.4.9</version> <type>jar</type> <scope>compile</scope> </dependency> |
2、Test.class
package com.cmcc.aoi.selfhelp.couchbase; import java.net.URI; import java.util.LinkedList; import java.util.List; import com.couchbase.client.CouchbaseClient; public class Test { public static void main(String[] args) { List<URI> uris = new LinkedList<URI>(); uris.add(URI.create("http://ip1:8091")); uris.add(URI.create("http://ip12:8091")); CouchbaseClient client = null; try { //*注意bucketPwd是bucket的密码,不是couchbase的密码 client = new CouchbaseClient(uris, "bucketName", "bucketPwd"); } catch (Exception e) { System.err.println("Error connecting to Couchbase: " + e.getMessage()); System.exit(0); } client.decr("key", 1); //减 client.incr("key", 1); //加 System.out.println(client.get("key")); } } |