Search code examples
servicestackservicestack.redis

ServiceStack Redis Client GetValues when value is not present and is a value type


Running ServiceStack.Redis.IRedisClient.GetValues<int?>, when any key is missing, I cannot map the values returned to keys. For example:

I ask for keys ("a1", "a2", "a3"). If there is no value associated with key "a2", it simply returns (1, 3).

But I need to map each of this value to its corresponding key. How can I do that?


Solution

  • You can use GetValuesMap to return a dictionary of keys with their associated values, e.g:

    var map = redis.GetValuesMap(new[] { "a1", "a2", "a3" }.ToList());
    

    Keys without values will have a corresponding null Dictionary value.