'How can I HGET from many hashes in one request in StackExchange.Redis?
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?
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Marc Gravell |
