Redis 支持的 ASP.NET SessionState 提供程序 [英] Redis backed ASP.NET SessionState provider
问题描述
我目前正在使用 Booksleeve 开发由 Redis 支持的 ASP.NET SessionState 自定义提供程序.Redis 似乎非常适合 SessionState(如果您必须使用它),因为:
I'm currently developing an ASP.NET SessionState custom provider that is backed by Redis using Booksleeve. Redis seemed like a perfect fit for SessionState (if you must use it) because:
- Redis 可以像 RDBMS 一样持久存储,但速度要快得多.
- 键/值数据存储区更适合 SessionState 的接口.
- 由于数据不是存储在进程中的(如默认的 Session 提供程序),SessionState 可以在 Web 服务器重启、崩溃等情况下存活.
- 如果需要,Redis 很容易进行水平分片.
所以,我想知道这是否对任何人有用,因为我们(我的公司)正在考虑在 GitHub 上开源它.想法?
So, I'm wondering if this will be useful to anyone since we (my company) are considering open sourcing it on GitHub. Thoughts?
我昨天确实发布了第一个版本:https://github.com/angieslist/AL-Redis/blob/master/AngiesList.Redis/RedisSessionStateStore.cs
I did release a first version of this yesterday: https://github.com/angieslist/AL-Redis/blob/master/AngiesList.Redis/RedisSessionStateStore.cs
推荐答案
我创建了一个基于 Redis 的 SessionStateStoreProvider
,它 可以在 GitHub 上找到,使用 ServiceStatck.Redis
作为客户端(而不是 Booksleeve).
I've created a Redis-based SessionStateStoreProvider
that can be found on GitHub using ServiceStatck.Redis
as the client (rather than Booksleeve).
它可以通过 NuGet 使用 Install-Package Harbour.RedisSessionStateStore
安装.
It can be installed via NuGet with Install-Package Harbour.RedisSessionStateStore
.
我发现@NathanD 的方法有一些怪癖.在我的实现中,锁与 会话值一起存储,而不是存储在单独的键中(减少到 Redis 的往返次数).此外,因为它使用 ServiceStack.Redis
,所以它可以使用池化连接.
I found a few quirks with @NathanD's approach. In my implementation, locks are stored with the session value rather than in a separate key (less round trips to Redis). Additionally, because it uses ServiceStack.Redis
, it can used pooled connections.
终于测试过了.这是我对@NathanD 方法的最大反感.如果不手动运行每个用例,就无法实际上知道它是否有效.
Finally, it's tested. This was my biggest turn off from @NathanD's approach. There was no way of actually knowing if it worked without running through every use case manually.
这篇关于Redis 支持的 ASP.NET SessionState 提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!