I have like 1000 hashes, and some of them has the same key, i.e.
Hash1 = {1: 1, 2: 1, 3: 5, 4: 7...}
Hash2 = {1: 4, 3: 5, 9: 7...}
Hash3 = {5: 4, 8: 5, 9: 7...}
...
I want to get all key 1
values in all hashes. I can do this:
List<value> values = new();
foreach (string hashKey in hashKeys)
{
values.Add(await _client.HashGetAsync(hashKey, "1"));
}
return values;
But this do network to Redis hashKeys.Count()
times. Can I do this in only one network request?
CodePudding user response:
Not directly via an inbuilt API - there is no single redis API that achieves this. However, you could use Lua (ScriptEvaluate
), passing in multiple keys, looping inside the Lua code, and building a result array by calling hget
repeatedly.