redis 加入key扫描
This commit is contained in:
@@ -124,6 +124,29 @@ class Redis {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<String>> scanKeys(String key, {int timeout = 30}) async {
|
||||||
|
List<String> keys = [];
|
||||||
|
int cursor = 0;
|
||||||
|
try {
|
||||||
|
do {
|
||||||
|
final result = await _command
|
||||||
|
?.send_object(['SCAN', cursor.toString(), 'MATCH', key]);
|
||||||
|
final List<dynamic> scanResult = result as List<dynamic>;
|
||||||
|
cursor = int.parse(scanResult[0] as String);
|
||||||
|
final List<dynamic> foundKeys = scanResult[1] as List<dynamic>;
|
||||||
|
|
||||||
|
keys.addAll(foundKeys.map((k) => k.toString()));
|
||||||
|
} while (cursor != 0);
|
||||||
|
|
||||||
|
// return await scanKeys(cmd, pattern)
|
||||||
|
// .timeout(Duration(seconds: timeoutSeconds));
|
||||||
|
} catch (e) {
|
||||||
|
print('Scan failed: $e');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RedisConfig {
|
class RedisConfig {
|
||||||
|
|||||||
Reference in New Issue
Block a user