【问题标题】:Why error No connection is available to service this operation: SETEX while writing to Redis Cache in C# console application and how to solve it为什么错误 No connection is available to service this operation: SETEX while writing to Redis Cache in C# console application 以及如何解决
【发布时间】:2020-04-10 07:03:24
【问题描述】:

我正在尝试将包含大约 5000 条记录的字典中的记录写入 Redis 缓存。但有时我会收到以下异常,我不知道为什么会收到此错误,我在互联网上检查过但找不到任何解决方案或此问题的根本原因。

using (ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("redis_server")))
            {
                IDatabase db = redis.GetDatabase();


                foreach (KeyValuePair<string, string> keyValuePair in _dictAllData)
                {
                    db.StringSet(keyValuePair.Key, keyValuePair.Value, TimeSpan.FromMinutes(30));
                }

        }

例外

没有可用的连接来服务这个操作:SETEX 747712; IOCP:(忙=0,空闲=1000,最小=4,最大=1000),工人: (忙=0,空闲=32767,最小=4,最大=32767),本地CPU:n/a

编辑:

StackExchange.Redis 版本:2.0.601

【问题讨论】:

    标签: c# redis stackexchange.redis redis-cache


    【解决方案1】:

    似乎您的连接池(客户端)中的连接已用完。此外,在性能方面,在这种情况下一次一组是不好的。

    您应该使用批处理或流水线。见Pipelining vs Batching in Stackexchange.Redis。它有代码示例。

    既然您似乎并不关心响应,请考虑flags: CommandFlags.FireAndForget。见Pipelines and Multiplexers

    【讨论】:

    • 我已经尝试了两种解决方案,流水线和批处理。两者都给出相同的先前错误。
    • 尝试将您的 StackExchange.Redis 版本降级到 2.0.519。 2.0.571 及更高版本有很多关于此问题的报告。见github.com/StackExchange/StackExchange.Redis/issues/1120
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-12
    • 2022-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多