簡體   English   中英

沒有可用於服務此操作的連接:SETEX 令牌; redis 緩存 Dotnet Framework 4.5 上的 SocketFailure

[英]No connection is available to service this operation: SETEX token; SocketFailure on redis cache Dotnet Framework 4.5

我正在嘗試將記錄寫入 Redis 緩存。 但有時我會遇到以下異常,

我不知道為什么會收到此錯誤

發生錯誤。","ExceptionMessage":"沒有可用於服務此操作的連接:SETEX 令牌; xxx.redis.cache.windows.net:6380/Subscription 上的 SocketFailure,來源:CheckForStaleConnection,輸入緩沖區:0,未完成:4,最后讀取:1 秒前,最后寫入:0 秒前,未答復寫入:1 秒前, keep-alive: 60s, pending: 0, state: ConnectedEstablishing, last-heartbeat: never, last-mbeat: -1s ago, global: 1s ago, manager: RecordConnectionFailed_ReportFailure, err: never; IOCP: (Busy=0,Free=1000,Min=4,Max=1000), WORKER: (Busy=1,Free=8190,Min=4,Max=8191), Local-CPU: n/a"," ExceptionType":"StackExchange.Redis.RedisConnectionException

我的連接多路復用器

private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
    {
        return ConnectionMultiplexer.Connect(ConfigurationManager.AppSettings["RedisConString"]);
    });


    public static ConnectionMultiplexer Connection
    {
        get { return lazyConnection.Value; }
    }


public bool Add(string key, string value, int expiryDays)
    {
        IDatabase cache = Connection.GetDatabase();

        cache.StringSet(key, value, TimeSpan.FromDays(expiryDays));

        return true;
    }

在這里閱讀https://stackexchange.github.io/StackExchange.Redis/Configuration.html

我遇到了同樣的問題,以下連接字符串對我有用。 我在我的連接字符串中添加了allowAdmin=True並且它起作用了。 我的 Redis 配置設置為僅允許 SSL 端口

redis-xxx-dev.redis.cache.windows.net:6380,allowAdmin=True,password=XXXX,ssl=True,abortConnect=False

這是我的 Redis 工廠,

public class RedisFactory
    {
        private static readonly Lazy<ConnectionMultiplexer> Connection;

#pragma warning disable CA1810 // Initialize reference type static fields inline
        static RedisFactory()
#pragma warning restore CA1810 // Initialize reference type static fields inline
        {
            var connectionString = ConfigHelper.Instance.RedisCacheConnectionString;
            var options = ConfigurationOptions.Parse(connectionString);

            Connection = new Lazy<ConnectionMultiplexer>(
                () => ConnectionMultiplexer.Connect(options)
            );
        }

        public static ConnectionMultiplexer GetConnection() => Connection.Value;
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM