Book Image

ServiceStack 4 Cookbook

Book Image

ServiceStack 4 Cookbook

Overview of this book

Table of Contents (18 chapters)
ServiceStack 4 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Using Redis Set data structures in ServiceStack


Sets in Redis are what you might expect—unordered, unique lists, similar to the HashSet class in .NET. You can try to add the same thing to Sets twice, but Redis will silently discard subsequent requests. Sets have some nice features in Redis: you can ask for the union of two sets to find out what unique values are present across multiple Sets, or you can ask for the intersection of two Sets to only see what values are shared. Sets are good at modeling the relationships between things, and tagging systems are often implemented in Sets for this reason.

Getting ready

For this example, we'll model the idea of allowing users our timeline service to tag people on to statuses. For instance, if I post Hello world! I might want to specify that two other people are involved. I can tag them on to my post.

A simple service interface might look something like the following:

curl -d "UserNames=Kyle&UserNames=Layoric&StatusId=b377c7c7013c47fdb72666576028210a...