skip to Main Content

I have a couchbase bucket of memcached type. I want to bulk get keys from the bucket. N1QL will not work as it is of memcached type. What is a good way to do this? I want to avoid multiple calls since per request, I have to fetch for around 100 keys at a time and don’t want to make so many connections at scale.

2

Answers


  1. If you can, it would be best to migrate to an "Ephemeral" bucket which still runs in memory but can be replicated, rebalanced, indexed, etc.

    Login or Signup to reply.
  2. As Graham Pople commented, if you know the document IDs, you can efficiently fetch many documents at once using the Couchbase Java SDK’s Reactive API.

    The documentation: Batching using the Coouchbase Java SDK’s Reactive API

    Here’s a slightly modified version of the most general code example from that documentation:

    List<String> docsToFetch = List.of("doc1", "doc2", "doc3");
    Map<String, Throwable> failedResults = new ConcurrentHashMap<>();
    
    List<GetResult> successfulResults = Flux.fromIterable(docsToFetch)
        .flatMap(key -> collection.reactive().get(key)
          .onErrorResume(e -> {
            failedResults.put(key, e);
            return Mono.empty();
          })
        )
        .collectList()
        .block();
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search