PooledRedisClientManager does not release connections

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.

+4
source share
2 answers

My biggest problem right now is that client connections are not closing.

You are using the "PooledRedisClientManager", so I understand that client connections should not be closed, but simply added to the pool for reuse. It looks like your pool size is 100 connections.

You can try using var mgr = new BasicRedisClientManager("localhost:6379") which should be at the disposal of the client.

+8
source

edit A suitable approach is not recommended - you should depend on the IRedisClientsManager and wrap all redis client calls inside the using () block, otherwise you will be bitten by gremlins.

I had similar problems so that Windsor played well with the PooledRedisClientsManager, in the end it worked:

  container.Register( Component.For<IRedisClientsManager>() .Instance(redisClients) .LifestyleSingleton(), Component.For<IRedisClient>() .UsingFactoryMethod(c => c.Resolve<IRedisClientsManager>().GetClient(), managedExternally: true)); } 

The managedExternally parameter reports that Windsor is not trying to use decommissioning issues in IRedisClients and allows the PooledRedisClientsManager to handle recirculation.

+2
source

All Articles