In BookSleeve there is a connection.Sets.GetAllString() method. What is the equivalent in StackExchange.Redis?
Thanks!
In BookSleeve there is a connection.Sets.GetAllString() method. What is the equivalent in StackExchange.Redis?
Thanks!
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...
Found it: connection.SetMembers(...) gets all the strings for a set from a key.