What is the equivalent of Sets.GetAllString() from BookSleeve in StackExchange.Redis?

149 views Asked by At

In BookSleeve there is a connection.Sets.GetAllString() method. What is the equivalent in StackExchange.Redis?

Thanks!

3

There are 3 answers

1
Fabian Nicollier On BEST ANSWER

Found it: connection.SetMembers(...) gets all the strings for a set from a key.

0
Pharao2k On

StringGet has an overload that takes an array of RedisKey-instances, so this would be the best way to get more than one string at once :)

0
Robert H. On

After a lot of searching, the best I can come up with is to abuse SetCombine(...). The basic concept is to ask redis to "combine" a single set and return the result. This will return all the values in that single set.

Also Sets.GetAllString(...) returned an array of strings. SetCombine returns an array of RedisValue. I wrote this little extension method to help refactor some code I am working on.

internal static class StackExchangeRedisExtentions
{
    internal static string[] SetGetAllString(this IDatabase database, RedisKey key)
    {
        var results = database.SetCombine(SetOperation.Union, new RedisKey[] { key });
        return Array.ConvertAll(results, item => (string)item);
    }
}

// usage
string key = "MySetKey.1";
string[] values = database.SetGetAllString(key);

I am not a fan of this solution. If I have missed something obvious, please let me know. I would be glad to get rid of this...