I save lists of json data in redis and access them using the ServiceStack C # client. I essentially manage my foreign keys, where I store zrange identifiers, and I use the internal interface for my application to pull the identifier from zrange , and then retrieve the json base objects from Redis and package them to return to other parts of my application.
I am using PooledRedisClientManager as I expect Redis to be hosted on another server from the server executing the code.
I do all my development work locally in Windows 8 using the MSOpenTech Redis server. My biggest problem right now is that client connections are not closing.
My Redis persister introduces an instance of IRedisClientManager (IoC - CastleWindsor). This code runs in the context of the azure working role.
This is how I extract elements from zrange:
public class MyRedisPersister<T> : IResourcePersister<T> { IRedisClientManager _mgr; public MyRedisPersister(IRedisClientManager mgr) { _mgr = mgr; } public IResourceList<T> Get<T>(string key, int offset, int count) where T { using (var redis = _clientManager.GetClient()) { var itemKeys = redis.GetRangeFromSortedSet(key, offset, offset + count - 1).ToList(); var totalItems = redis.GetSortedSetCount(key); if (itemKeys.Count == 0) { return new ResourceList<T> { Items = new List<T>(), Offset = 0, PageSize = 0, TotalItems = 0, TotalPages = 0 }; } else { return new ResourceList<T> { Items = itemKeys.Select(k => redis.Get<T>(k)).ToList(), Offset = offset, PageSize = count, TotalItems = totalItems, TotalPages = (int) Math.Ceiling((float) totalItems/count) }; } } } }
This is the code I use to register IRedisClientManager
var mgr = new PooledRedisClientManager(100, 10, "localhost:6379"); container.Register(Component.For<IRedisClientsManager>().Instance(mgr).LifeStyle.Singleton);
Any help would be greatly appreciated.