How to do .Get<T>(List keys) in SDK 3.x in C#?

@Brian_Davis that method actually had some issues with regard to how efficiently it parallelized the operations in 2.x, and is not part of the 3.x design. Part of the problem is that the most efficient way to parallelize is going to vary widely by use case. Things like expected document size, number of data nodes, network latency, and configured connection pool size can all affect how many operations can be efficiently run in parallel.

My recommendation is to parallelize the operations yourself. For a small set of documents (say, a couple dozen), you don’t need to worry about anything fancy.

var keys = new[] {"document_1", "document_2", "document_3"};
var tasks = keys.Select(p => bucket.GetAsync(p)).ToList();

await Task.WhenAll(tasks); // Note: This line will throw an exception if ANY of the gets fail

var results = tasks.Select(p => p.Result).ToList();

If you’re trying to get a large number of documents, you may want to implement a limiter to keep the number of in-flight operations under control. For very large numbers of documents, I recommend grouping the requests into parallel batches for the best efficiency.

If you have more specifics about your use case, I’m happy to provide more details.

2 Likes