I have need to store an unordered set of items in a manner that allows for fast
- Insert
- Membership testing (and/or intersection)
- Random subset retrieval
Redis seems like a great candidate for this kind of storage, but as I read the docs, there's not one data type that fits this perfectly. Having a SUBSET command for the Set type would be perfect.
What's the best way to stor开发者_Python百科e and query this kind of data structure?
In what way does the regular Redis set not meet your criteria? Inserts and membership testing/intersection are obviously built in. Sets also have SRANDMEMBER to retrieve a random member of a set. You could call it multiple times to retrieve a subset of items (though there is the potential to get the same member back multiple times.
If the size of the set is large, and the size of the subset is small, this likely would not be that big of a deal. It gets trickier as the size of the subset grows compared to the size of the overall set (though eventually it gets cheaper to just randomly select the items that you don't want in the subset and then just do a set difference on it).
精彩评论