From a34d58f93eb692c976d1be165920a03a54dea027 Mon Sep 17 00:00:00 2001 From: qmqz Date: Tue, 20 Jan 2026 10:03:56 +0800 Subject: [PATCH] =?UTF-8?q?redis=20=E5=8A=A0=E5=85=A5key=E6=89=AB=E6=8F=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/base/redis/redis.dart | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/base/redis/redis.dart b/lib/base/redis/redis.dart index 543ce48..a247d1d 100644 --- a/lib/base/redis/redis.dart +++ b/lib/base/redis/redis.dart @@ -124,6 +124,29 @@ class Redis { return false; } } + + Future> scanKeys(String key, {int timeout = 30}) async { + List keys = []; + int cursor = 0; + try { + do { + final result = await _command + ?.send_object(['SCAN', cursor.toString(), 'MATCH', key]); + final List scanResult = result as List; + cursor = int.parse(scanResult[0] as String); + final List foundKeys = scanResult[1] as List; + + 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 {