Couchbase Client Java
来源:互联网 发布:四平软件 怎么样 编辑:程序博客网 时间:2024/05/22 16:04
javac -cp couchbase-client-1.0.3.jar:spymemcached-2.8.2.jar Main.java
java -cp .:couchbase-client-1.0.3.jar:spymemcached-2.8.2.jar:jettison-1.1.jar:netty-3.2.0.Final.jar:commons-codec-1.5.jar Main
Java客户端会自动判断数据大小,决定是否启用客户端压缩。跨语言使用可能导致Java存的数据不能被C客户端读取,因此需要关闭客户端压缩。
关闭客户端压缩
SerializingTranscoder st = (SerializingTranscoder)client.getTranscoder();
st.setCompressionThreshold(Integer.MAX_VALUE);
import java.net.URI;import java.util.LinkedList;import java.util.List;import java.util.concurrent.TimeUnit;import com.couchbase.client.CouchbaseClient;import net.spy.memcached.internal.GetFuture;import net.spy.memcached.internal.OperationFuture;public class Main { public static final int EXP_TIME = 10; public static final String KEY = "spoon"; public static final String VALUE = "Hello World!"; public static void main(String args[]) { // Set the URIs and get a client List<URI> uris = new LinkedList<URI>(); Boolean do_delete = false; // // Connect to localhost or to the appropriate URI uris.add(URI.create("http://10.10.135.40:8091/pools")); CouchbaseClient client = null; try { client = new CouchbaseClient(uris, "default", ""); } catch (Exception e) { System.err.println("Error connecting to Couchbase: " + e.getMessage()); System.exit(0); } // Do an asynchronous set OperationFuture<Boolean> setOp = client.set(KEY, EXP_TIME, VALUE); // Do a synchrononous get Object getObject = client.get(KEY); // Do an asynchronous get GetFuture getOp = client.asyncGet(KEY); // Do an asynchronous delete OperationFuture<Boolean> delOp = null; if (do_delete) { delOp = client.delete(KEY); } // Shutdown the client // client.shutdown(3, TimeUnit.SECONDS); // Now we want to see what happened with our data // Check to see if our set succeeded try { if (setOp.get().booleanValue()) { System.out.println("Set Succeeded"); } else { System.err.println("Set failed: " + setOp.getStatus().getMessage()); } } catch (Exception e) { System.err.println("Exception while doing set: " + e.getMessage()); } // Print the value from synchronous get if (getObject != null) { System.out.println("Synchronous Get Suceeded: " + (String) getObject); } else { System.err.println("Synchronous Get failed"); } // Check to see if ayncGet succeeded try { if ((getObject = getOp.get()) != null) { System.out.println("Asynchronous Get Succeeded: " + getObject); } else { System.err.println("Asynchronous Get failed: " + getOp.getStatus().getMessage()); } } catch (Exception e) { System.err.println("Exception while doing Aynchronous Get: " + e.getMessage()); } long startTime = System.currentTimeMillis(); int count = 10000; for(int i = 0; i < count; i++) { Object getObjectEx = client.get(KEY); if(getObject == null) System.err.println("Synchronous Get failed"); } long endTime = System.currentTimeMillis(); System.out.println("QPS:" + count * 1000 / (endTime - startTime) ); client.shutdown(3, TimeUnit.SECONDS); // Check to see if our delete succeeded if (do_delete) { try { if (delOp.get().booleanValue()) { System.out.println("Delete Succeeded"); } else { System.err.println("Delete failed: " + delOp.getStatus().getMessage()); } } catch (Exception e) { System.err.println("Exception while doing delete: " + e.getMessage()); } } }}
阅读全文
0 0
- Couchbase Client Java
- Couchbase Java Client Library 1.1
- couchbase-java-client-2.0.2.jar版本客户端的操作
- Couchbase Client Python
- CouchBase
- couchbase
- NuGet安装,通过NuGet安装Couchbase Client Library for .NET
- java client
- Couchbase之环境搭建与Java小试
- Couchbase之环境搭建 与 基于Java的测试
- Memcache升级版之CouchBase [三]JAVA应用详解
- Couchbase备份
- Couchbase Architecture
- couchbase swappiness
- 安装 CouchBase
- Couchbase简介
- couchbase使用
- couchbase view
- 自己动手写RTP服务器——用RTP协议传输TS流
- iOS逆向 微信屏蔽群消息
- 排序整理
- 如何对List分段操作
- arm学习心得
- Couchbase Client Java
- 49 WebGL绘制透明的图形
- namenode启动过程
- 【0008】mysql5.6免安装版下载配置教程
- Nginx简介及配置文件详解
- 当程序员写不出代码了,我该怎么办?
- CSS&JS
- ListView和Adapter数据适配器的简单介绍
- hibernate增删改查