【问题标题】:StackExchange.Redis Lazy connection configurationStackExchange.Redis 延迟连接配置
【发布时间】:2015-07-23 05:00:50
【问题描述】:

我正在尝试通过 StackExchange.Redis 库实现 Redis 缓存服务。

我的 Redis 客户端:

public class RedisClient
    {
        private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
        {
            return ConnectionMultiplexer.Connect(string.Format("{0},{1}",
                        ConfigurationManager.AppSettings.GetStringOrDefault("redis_masters", "someIP1:6379"),
                        ConfigurationManager.AppSettings.GetStringOrDefault("redis_slaves", "someIP2:6379")));
        });

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

我尝试以这种方式建立连接:

using (var redis = RedisClient.GetConnection)
{
    ...
}

我收到异常:“无法连接到 redis 服务器;要创建断开连接的多路复用器,请禁用 AbortOnConnectFail。PING 上的 UnableToResolvePhysicalConnection”

我还尝试向连接添加一些配置,如下所示:

ConnectionMultiplexer.Connect(string.Format("{0},{1},Ssl=false"

我得到另一个异常:“ValueFactory 试图访问此实例的 Value 属性。”

我与 Redis 的连接在另一个库中运行良好:"StackExchange.Redis" 我只是尝试迁移到"ServiceStack.Redis" 我错过了什么?

【问题讨论】:

    标签: c# asp.net stackexchange.redis


    【解决方案1】:

    在配置中使用密码

    ConnectionMultiplexer.Connect("localhost,password=XXXXX");
    

    【讨论】:

      猜你喜欢
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-18
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多