Couchbase 批量检索 Java 中的多个键
Couchbase bulk retrieving multiple keys in Java
在 couchbase 中,考虑一个文档有一个字段,其中包含一组引用其他文档的键
{
"some_ids": ["otherdoc1", "otherdoc2", "otherdoc3"]
}
这两种检索 some_ids
字段中所有文档的解决方案中哪一种提供最佳性能?
-
List<JsonDocument> foundDocs = Observable
.just("otherdoc1", "otherdoc2", "otherdoc3")
.flatMap(new Func1<String, Observable<JsonDocument>>() {
@Override
public Observable<JsonDocument> call(String id) {
return bucket.async().get(id);
}
})
.toList()
.toBlocking()
.single();
创建设计视图,然后使用 startKey
和 endKey
检索其索引的子集
// Map function
function(doc, meta) {
if (doc.type == 'otherdoc') {
emit(meta.id, doc);
}
}
// ViewQuery (in a java method)
ViewQuery.from('designOther', 'viewOther')
.startKey('otherdoc1')
.endKey('otherdoc2');
在 Couchbase 中,当您知道密钥时,SDK 知道向哪个节点请求该密钥(通过散列)。另一方面,查询视图意味着视图引擎联系集群中的每个节点。
所以在 RxJava 中直接获取 && 批处理,因为你知道密钥,将节省你额外的往返行程,并且最终应该表现得更好!
在 couchbase 中,考虑一个文档有一个字段,其中包含一组引用其他文档的键
{
"some_ids": ["otherdoc1", "otherdoc2", "otherdoc3"]
}
这两种检索 some_ids
字段中所有文档的解决方案中哪一种提供最佳性能?
-
List<JsonDocument> foundDocs = Observable .just("otherdoc1", "otherdoc2", "otherdoc3") .flatMap(new Func1<String, Observable<JsonDocument>>() { @Override public Observable<JsonDocument> call(String id) { return bucket.async().get(id); } }) .toList() .toBlocking() .single();
创建设计视图,然后使用
检索其索引的子集startKey
和endKey
// Map function function(doc, meta) { if (doc.type == 'otherdoc') { emit(meta.id, doc); } } // ViewQuery (in a java method) ViewQuery.from('designOther', 'viewOther') .startKey('otherdoc1') .endKey('otherdoc2');
在 Couchbase 中,当您知道密钥时,SDK 知道向哪个节点请求该密钥(通过散列)。另一方面,查询视图意味着视图引擎联系集群中的每个节点。
所以在 RxJava 中直接获取 && 批处理,因为你知道密钥,将节省你额外的往返行程,并且最终应该表现得更好!