Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedisClientPool占用内存大,系统用到了Redis订阅功能,能否限制RedisClientPool的数量,附图 #143

Open
binjinshi123 opened this issue Apr 26, 2023 · 4 comments

Comments

@binjinshi123
Copy link

binjinshi123 commented Apr 26, 2023

1
2
3

@2881099
Copy link
Owner

2881099 commented Apr 26, 2023

请提供测试 demo

@binjinshi123
Copy link
Author

    /// <summary>
    /// redis
    /// </summary>
    protected RedisClient rds;

    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="connectionStrings"></param>
    public VERedisCache(string[] connectionStrings)
    {
        if (VEConfig.CfgOnConsul.Redis.IsCluster)
        {
            rds = new RedisClient(new ConnectionStringBuilder[] { String.Join(",", connectionStrings) });
        }
        else
        {
            rds = new RedisClient(String.Join(",", connectionStrings));
        }
        rds.Serialize = obj => JsonConvert.SerializeObject(obj);
        rds.Deserialize = (json, type) => JsonConvert.DeserializeObject(json, type);

        //rds.Notice += (s, e) => Console.WriteLine($"{s}: {e.Log}" );
        //this.rds = new RedisClient((p => { return null; }), connectionStrings);
    }

    /// <summary>
    /// 订阅,根据分区规则返回SubscribeObject,
    /// Subscribe(("chan1", msg => Console.WriteLine(msg.Body)), ("chan2", msg => Console.WriteLine(msg.Body)))
    /// </summary>
    /// <param name="channels">频道和接收器</param>
    /// <returns></returns>
    public void Subscribe(Action<string, object> onMessage)
    {
         this.rds.PSubscribe(new string[] { VEDistributedCache.Cst_SubKey }, onMessage);
    }

    /// <summary>
    /// 订阅,根据分区规则返回SubscribeObject,
    /// Subscribe(("chan1", msg => Console.WriteLine(msg.Body)), ("chan2", msg => Console.WriteLine(msg.Body)))
    /// </summary>
    /// <param name="channels">频道和接收器</param>
    /// <returns></returns>
    public void UnSubscribe()
    {
        this.rds.UnSubscribe(new string[] { VEDistributedCache.Cst_SubKey });
    }

    /// <summary>
    /// 用于将信息发送到指定分区节点的频道,最终消息发布格式:1|message
    /// </summary>
    /// <param name="channel">频道名</param>
    /// <param name="message">消息文本</param>
    /// <returns></returns>
    public long Publish(string channel, string message)
    {
        return this.rds.Publish(channel, message);
    }

@binjinshi123
Copy link
Author

生产环境运行,目前没有找到可疑的点

@2881099
Copy link
Owner

2881099 commented Apr 29, 2023

你每次都 new 这个类吗?请提供完整的测试 demo,否则细节一直询问,沟通效率低。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants