/// <summary> /// 获取Redis的IDatabase /// </summary> /// <param name="db">存储库位置</param> /// <param name="redisServer">连接串配置[枚举表示]</param> /// <returns></returns> public static IDatabase GetDB(int db = -1, DictRedisServer redisServer = DictRedisServer.RedisHost) { var redisServerKey = DictRedisServer.RedisHost.ToString(); if (!_creaters.TryGetValue(redisServerKey, out ConnectionMultiplexer con) || !con.IsConnected) { lock (_locker) { if (!_creaters.TryGetValue(redisServerKey, out con) || !con.IsConnected) { try { con = ConnectionMultiplexer.Connect(RedisConfig.GetRedisServer(redisServerKey)); con.ConnectionFailed += MuxerConnectionFailed; con.ConnectionRestored += MuxerConnectionRestored; con.ErrorMessage += MuxerErrorMessage; con.ConfigurationChanged += MuxerConfigurationChanged; con.HashSlotMoved += MuxerHashSlotMoved; con.InternalError += MuxerInternalError; _creaters[redisServerKey] = con; } catch (Exception ex) { //LogHelper.Error($"init-connectionMultiplexer:{DictRedisServer.YX_Manager_DataLoader_RedisHost}\r\n{ex}"); } } } } return(con?.GetDatabase(db)); }
private static ConnectionMultiplexer GetManager() { var server = RedisConfig.GetRedisServer(DictRedisServer.RedisHost.ToString()); return(ConnectionMultiplexer.Connect(server)); }