Beispiel #1
0
        /// <summary>
        /// 获取连接字符串
        /// </summary>
        /// <param name="endpoint">Redis终端</param>
        /// <returns></returns>
        public string GetConnectionString(RedisEndpoint endpoint)
        {
            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(endpoint.Host) && endpoint.Port > 0)
            {
                sb.Append($"{endpoint.Host}:{endpoint.Port}");
            }

            if (!string.IsNullOrWhiteSpace(endpoint.Password))
            {
                sb.Append($",password={endpoint.Password}");
            }

            if (endpoint.DbIndex > 0)
            {
                sb.Append($",defaultDatabase={endpoint.DbIndex}");
            }

            if (endpoint.Timeout > 0)
            {
                sb.Append($",connectTimeout={endpoint.Timeout}");
            }

            return(sb.ToString());
        }
Beispiel #2
0
 /// <summary>
 /// 设置默认连接字符串
 /// </summary>
 /// <param name="endpoint"></param>
 public static void SetDefaultConnectionStr(RedisEndpoint endpoint)
 {
     _redisConnectionString = endpoint.GetConnectionString();
 }
Beispiel #3
0
 public void Initialize(RedisEndpoint endpoint)
 {
     Client = new RedisCacheClient();
     _redis = Client.GetClient(endpoint, 1000);
     _db    = _redis.GetDatabase();
 }