Skip to content

Commit ee4e257

Browse files
committed
更新版本号至2025.08.19.14.00,移除docker-image.yml文件,优化Redis操作使用SCAN命令替代KEYS命令
1 parent 8e56256 commit ee4e257

3 files changed

Lines changed: 22 additions & 35 deletions

File tree

.github/workflows/docker-image.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qwen2api",
3-
"version": "2025.08.18.17.20",
3+
"version": "2025.08.19.14.00",
44
"main": "src/server.js",
55
"scripts": {
66
"start": "node src/start.js",

src/utils/redis.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,16 @@ const getAllAccounts = async () => {
197197
try {
198198
const client = await ensureConnection()
199199

200-
const keys = await client.keys('user:*')
200+
// 使用SCAN命令替代KEYS命令,避免阻塞Redis服务器
201+
const keys = []
202+
let cursor = '0'
203+
204+
do {
205+
const result = await client.scan(cursor, 'MATCH', 'user:*', 'COUNT', 100)
206+
cursor = result[0]
207+
keys.push(...result[1])
208+
} while (cursor !== '0')
209+
201210
if (!keys.length) {
202211
logger.info('没有找到任何账户', 'REDIS', '✅')
203212
return []
@@ -364,7 +373,17 @@ const redisClient = {
364373

365374
async keys(pattern) {
366375
const client = await ensureConnection()
367-
return client.keys(pattern)
376+
// 使用SCAN命令替代KEYS命令,避免阻塞Redis服务器
377+
const keys = []
378+
let cursor = '0'
379+
380+
do {
381+
const result = await client.scan(cursor, 'MATCH', pattern, 'COUNT', 100)
382+
cursor = result[0]
383+
keys.push(...result[1])
384+
} while (cursor !== '0')
385+
386+
return keys
368387
},
369388

370389
async del(key) {

0 commit comments

Comments
 (0)