PooledRedisClientManager没有释放连接 [英] PooledRedisClientManager not releasing connections

查看:2397
本文介绍了PooledRedisClientManager没有释放连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我存储JSON数据列表中的Redis和使用ServiceStack C#客户端访问它。我基本上是管理我自己的外键,我在那里存放 zrange 的id和我使用内部接口到我的应用程序从拉的id的 zrange ,然后从Redis的获取底层的JSON对象并将其打包作为一个列表返回到我的应用程序的其他部分。

I am storing lists of json data in redis and accessing it using the ServiceStack c# client. I am essentially managing my own foreign keys, where I store a zrange of ids and I use an interface internal to my application to pull the id's from the zrange and then fetch the underlying json objects from Redis and package them as a list to return to other parts of my application.

我使用在 PooledRedisClientManager ,因为我预料的Redis从执行代码的服务器不同的服务器上托管。

I am using the PooledRedisClientManager as I anticipate Redis to be hosted on a different server from the server executing the code.

我做我所有的开发工作在本地的Windows 8,使用Redis的MSOpenTech服务器。目前我最大的挑战是,客户端连接不被关闭。

I am doing all my development work locally on Windows 8, using the MSOpenTech Redis server. Currently my biggest challenge is that client connections are not being closed.

我Redis的持留正在与 IRedisClientManager 的一个实例注入(国际奥委会CastleWindsor)。这个代码执行中的蔚蓝工作者角色上下文

My Redis persister is being injected with an instance of IRedisClientManager (IoC is CastleWindsor). This code executes in the context of an azure worker role.

这是我如何从zrange获取项目:

This is how I am fetching items from a 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)
                    };
            }
        }
    }
}

这是我用来注册 IRedisClientManager

var mgr = new PooledRedisClientManager(100, 10, "localhost:6379");
container.Register(Component.For<IRedisClientsManager>().Instance(mgr).LifeStyle.Singleton);



任何帮助将不胜感激。

Any help would be greatly appreciated.

推荐答案

目前我最大的挑战是,客户端连接不被关闭。

您正在使用PooledRedisClientManager所以我的理解是,客户端连接不应该被关闭,只是把入池重用。它看起来像你的池大小为100个连接。

You are using the 'PooledRedisClientManager' so my understanding is that the client connections should not be closed, just put into the pool for reuse. It looks like your pool size is 100 connections.

您可以尝试使用
VAR经理=新BasicRedisClientManager(本地主机:6379)
应该处理的客户端。

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

这篇关于PooledRedisClientManager没有释放连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆