Using Redis on Windows with ServiceStack

Posted on 03. Apr, 2012 by in Blog, Coding

While Redis is well supported on *nix platforms, its not so much on Windows.  As I plan on utilizing .net and SQL server, I need to use something that works in Windows.  I tried using Couchbase’s version of memcached, but never got it working properly through ServiceStack’s memcached add-on.  Plus, the install seemed very heavy for my currently simple needs to cache some data during user login.

So, I hit Google to find a Redis on Windows solution. I first came across this one…

https://github.com/dmajkic/redis/downloads

…which is nice, but is not service based.  I wanted something that will run as a Windows service and came across this fork…

https://github.com/rgl/redis

…which installs the redis port as a Windows service.

Now in my asp.net mvc site, in the ServiceStack App_Start in the container, I can register it as the Cache client…

container.Register(c => new PooledRedisClientManager("localhost:6379"));
container.Register(c => (ICacheClient)c.Resolve());

Now in my base controller, I specified…

public ICacheClient CacheClient { get; set; }
protected override void OnAuthorization(AuthorizationContext filterContext) {
using (CacheClient) {
string cacheAccountKey = IdUtils.CreateUrn(SessionKey + "account");
AccountModel account = CacheClient.Get(cacheAccountKey);
// ...
}

…which now goes against the Redis server.

I don’t know how stable it is yet, and whether I would consider this for a production site, but given the few Windows options, I might not have a lot of choices.  Thanks to ServiceStack, Redis, and the folks who helped port it to Windows to at least get me this far :-) .

4 Responses to “Using Redis on Windows with ServiceStack”

  1. redsquare 3 April 2012 at 3:46 pm #

    Why not run a simple linux server in a vm?

  2. clippersoft 3 April 2012 at 3:52 pm #

    Honestly, because I’m afraid of performance and overhead of running a separate server for the memory caching. I wanted something local, because I wanted it to be pulled from memory as fast as possible, and having to access another server might add too much overhead. Also, that would take away from my VPS’ resources to run a separate VM OS.

    Have you run it in a separate VM and seen reasonable performance with not a major overhead?

    Thanks for the input.

  3. M. David Peterson 3 April 2012 at 4:33 pm #

    Apparently WP doesn’t like my use of < and >. Please feel free to delete my previous to comments, replaced instead by the following:

    Microsoft is working on an official redis port to Windows which they announced this last December by releasing a patch via a gist: https://gist.github.com/1439660. They’ve since created an official github-based project under the ‘microsoft-interop’ organization: https://github.com/Microsoft-Interop/redis.git. While it’s nowhere near production ready, they made significant inroads into solving the performance bottleneck caused by the lack of fork (or equivalent) support on Windows that keeps the current ‘official’ Windows port: https://github.com/dmajkic/redis tagged with the ‘for development only’ label.

  4. clippersoft 3 April 2012 at 7:56 pm #

    Thanks – I saw that out there and while I was a bit surprised they were doing that, I very much look forward to them releasing a production stable redis port.


Leave a Reply

Your April Price - Only $58!