Пример #1
0
        /// <summary>
        /// 创建redis订阅链接
        /// </summary>
        /// <param name="redisUri"></param>
        /// <returns></returns>
        public static ISubscriber GetSubscriber(string redisUri = "")
        {
            var config = new RedisClientConfigurations {
                Url = redisUri
            };
            var client = RedisClient.GetRedisClient(config);

            if (client.IsConnected)
            {
                client.PreserveAsyncOrder = config.PreserveAsyncOrder;
                return(client.GetSubscriber());
            }
            else
            {
                throw new ArgumentException("RedisHelper.client", $"Redis订阅未能成功连接。连接配置为{config.ToJson()}");
            }
        }
Пример #2
0
        /// <summary>
        /// 创建redis链接
        /// </summary>
        /// <param name="dbNum"></param>
        /// <param name="defaultKey"></param>
        /// <param name="redisUri"></param>
        /// <returns></returns>
        public static IDatabase GetDatabase(int dbNum = 0, string redisUri = "")
        {
            var config = new RedisClientConfigurations {
                Url = redisUri
            };
            var client = RedisClient.GetRedisClient(config);

            if (client.IsConnected)
            {
                return(client.GetDatabase(db: dbNum));
            }
            else
            {
                throw new ArgumentException("RedisHelper.client", $"Redis未能成功连接。连接配置为{config.ToJson()}");
            }
        }