2

So I need to access in bulk many different hashes (in StackExchange.Redis, I have different RedisKey's).

What is the best (fastest) way to do it? For example, for these two possible implementations, is either correct? Which one works better?

1.

List<Task<HashEntry[]>> list = new List<Task<HashEntry[]>>();
List<RedisKey> keys; //Previously initialized list of keys
foreach (var key in keys)
{
    var task = db.HashGetAllAsync(key);
    list.Add(task);
}
await Task.WhenAll(list);
List<Task<HashEntry[]>> list = new List<Task<HashEntry[]>>();
List<RedisKey> keys; //Previously initialized list of keys
IBatch batch = db.CreateBatch();
foreach (var key in keys)
{
    var task = batch.HashGetAllAsync(key);
    list.Add(task);
}
batch.Execute();
0

1 Answer 1

3

On performance: have you timed them?

Other than that: both work, and have different trade-offs; the latter is synchronous, for example - bit benefits from avoiding all of the TPL overheads and complications. You might also want to consider a third option - a Lua script that accepts and array of keys as input and invokes HGETALL for each.

Sign up to request clarification or add additional context in comments.

1 Comment

Hello. I tried the three of them ... oddly (for me) the winner (and sometimes by a large margin) was "pipelining" (calling HashGetAllAsync multiple times and awaiting). I say oddly because reading on the internet, Lua seemed to be a superior solution. Maybe I am using a bad script? I am using a similar script to the one posted here link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.