0

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

Thanks!

Fabian Nicollier
  • 2,811
  • 1
  • 23
  • 19

3 Answers3

0

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 :)

Pharao2k
  • 685
  • 4
  • 24
0

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

Fabian Nicollier
  • 2,811
  • 1
  • 23
  • 19
0

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...

Robert H.
  • 5,864
  • 1
  • 22
  • 26