diff --git a/lib/base/redis/redis.dart b/lib/base/redis/redis.dart index a247d1d..ae5165b 100644 --- a/lib/base/redis/redis.dart +++ b/lib/base/redis/redis.dart @@ -30,6 +30,24 @@ class Redis { try { _command = await RedisConnection().connect(_config.host, _config.port); print('Redis Connected successfully!'); + if (_config.password != null) { + var authResult = + await _command!.send_object(['AUTH', _config.password]); + if (authResult == "OK") { + print('Redis Authentication successfully'); + } else { + print('Redis Authentication failed'); + connect(reconnect: reconnect); + } + } + if (_config.database != 0) { + var result = await _command! + .send_object(["SELECT", _config.database.toString()]); + if (result == "OK") { + print('Redis use db ${_config.database}'); + } + } + _connected = true; //定时检测是否断开连接 Future.delayed(Duration(seconds: 1), () async { @@ -152,9 +170,13 @@ class Redis { class RedisConfig { String host; int port; + String? password; + int database; RedisConfig({ required this.host, this.port = 6379, + this.password, + this.database = 0, }); }