1

When trying to write a large amount of keys and values to the DB concurrently using the _db.HashSetAsync(...) function I noticed that many values are actually not written to the DB but there is no exception or error.

How do I know if the HashSet call has been successful or not? I want to know if my values were written.

My code looks something like the following:

var _redis = ConnectionMultiplexer.Connect("localhost");
var _db = _redis.GetDataBase();

await Task.Run(() => 
{
    Parallel.For(0,10000,
    async index => {await _db.HashSetAsync("id:"+i, new HashEntry[] {new HashEntry("Field","value")});});
}); 

When I checked, the database has way fewer keys than 10000. Is something wrong in my code? How do I know which HashSetAsync call has worked and which hasn't?

user194878
  • 183
  • 1
  • 7
  • The `Parallel.For`/`Parallel.ForEach` cannot be used with `async` delegate. You can use the `Parallel.ForEachAsync` instead, passing an `Enumerable.Range` as `source`. – Theodor Zoulias Jun 06 '23 at 14:05

0 Answers0