/// <summary> /// 关闭连接 /// </summary> public static void Dispose() { _conn?.Close(); _dbIndex = -1; _logger = null; _prefix = null; }
/// <summary> /// 初始化Redis连接 /// </summary> /// <param name="connStr"></param> /// <param name="prefix"></param> /// <param name="logger"></param> /// <param name="dbIndex"></param> public static void Init(string connStr, string prefix, int dbIndex = 0, StackBaseLogger logger = null) { if (string.IsNullOrWhiteSpace(connStr)) { throw new Exception("Redis连接字符串不能为空"); } _conn = ConnectionMultiplexer.Connect(connStr, logger); _prefix = prefix; _dbIndex = dbIndex; _logger = logger; //注册事件 _conn.ConnectionFailed += Redis_ConnectionFailed; _conn.ErrorMessage += Redis_ErrorMessage; _conn.ConnectionRestored += Redis_ConnectionRestored; }
/// <summary> /// 初始化Redis连接 /// </summary> /// <param name="config"></param> /// <param name="prefix"></param> /// <param name="logger"></param> /// <param name="dbIndex"></param> public static void Init(ConfigurationOptions config, string prefix, int dbIndex = 0, StackBaseLogger logger = null) { Init(config.ToString(), prefix, dbIndex, logger); }