ASP.NET Redis Providers

Back when I fell in love with Redis I started writing a session state provider for with redis as the backend. I did this because at the time my company was using SQL Server as a state store for our web farm. While this is not a great idea because there are better options SQL Server is what we knew. So in my spare time I wrote the first iteration of ASP.NET Redis Providers.

This session state provider follows the original design of a locking session state provider because applications are multithreaded. Meaning to request could potentially fight over the same object. It is also cooler than SQL implementation because no item expiration callback, and you can tune persistence on Redis for better performance. You can be really safe and flush after every key change, flush after a bunch of changes or even never flush to disk.

The session state provider was a great success, so I decided I would try my hand a few more providers.

Borat Great Success

Natually the next two providers I worked on were the next two most used, membership and role. The membership provider isn't really a complete implementation of the full membership provider base class because there are searching features that are not easily implemented in Redis and I believe the cost of implementing them would bloat the database too much. Feel free to fork it on github and implement if you like. There is also there a strangeness around getting online users and get all users. I had to store a list of all the users so that I can then get the user by key for the GetAllUser call. For getting users that are online I could have pulled all the user information and then query the last login time but instead we store a separate key as a sorted set and get the users last logged in time by getting the length or a range query on the sorted set.

On the other hand, the role provider was a natural fit with Redis. The roles are stored as a set. The user's roles are stored as a set and the role's users are stored a set. Fits nicely with Redis and it extremly simple implementation.

Since all of these provider worked like a champ so I decided this is something I could give back to the .NET community because I have been using so many open source projects in my own development for years. Shout out to the dependencies JSON.NET and Booksleeve.

Since open sourcing, I implemented web event provider and profile provider. I also implemented a output cache provider and a non locking session state provider. The web event provider is basically a log which is not really the best fit for Redis. The profile provider suffers from the same bloat with searching the users as the membership provider. The output cache provider allows caching of page results for multiple web servers that are serving the same pages to users. The non locking session state provider breaks the existing idea of the default session state provider implementation so use with caution unless you know want you are doing.

You can install it from nuget.