Skip to content

Conversation

@lgphone
Copy link
Contributor

@lgphone lgphone commented Dec 16, 2025

  • 使用 Redis SCAN 替代 KEYS,避免大数量扫描时阻塞 Redis
  • SCAN 为官方推荐的非阻塞方案
  • 不影响现有缓存语义

@gru-agent
Copy link
Contributor

gru-agent bot commented Dec 16, 2025

TestGru Assignment

Summary

Link CommitId Status Reason
Detail ce88915 🚫 Skipped No files need to be tested {"packages/service/common/cache/index.ts":"File path does not match include patterns.","packages/service/common/redis/index.ts":"File path does not match include patterns."}

History Assignment

Tip

You can @gru-agent and leave your feedback. TestGru will make adjustments based on your input

@github-actions
Copy link

github-actions bot commented Dec 16, 2025

Preview sandbox Image:

registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-pr:fatsgpt_sandbox_7d78d5254927d097537abe60bd81498ee2ce30a7

@github-actions
Copy link

github-actions bot commented Dec 16, 2025

Preview mcp_server Image:

registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-pr:fatsgpt_mcp_server_7d78d5254927d097537abe60bd81498ee2ce30a7

@github-actions
Copy link

github-actions bot commented Dec 16, 2025

Preview fastgpt Image:

registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-pr:fatsgpt_7d78d5254927d097537abe60bd81498ee2ce30a7

@c121914yu c121914yu requested a review from Copilot December 16, 2025 15:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces blocking Redis KEYS operations with non-blocking SCAN commands to prevent Redis from being blocked during large-scale key scans. The changes implement the officially recommended pattern for iterating over keys in production environments while maintaining existing cache semantics.

Key Changes

  • Replaced KEYS command with SCAN in getAllKeysByPrefix function to iterate through keys non-blockingly
  • Updated refreshVersionKey to use SCAN with pipelined deletions for efficient batch processing
  • Added mock support for scan and pipeline operations in test utilities

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/service/common/redis/index.ts Refactored getAllKeysByPrefix to use SCAN with cursor-based iteration instead of blocking KEYS
packages/service/common/cache/index.ts Updated refreshVersionKey to use SCAN for pattern matching and pipelined deletions for batch operations
test/mocks/common/redis.ts Added mock implementations for scan and pipeline operations to support new Redis patterns

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

sismember: vi.fn().mockResolvedValue(0)
sismember: vi.fn().mockResolvedValue(0),

// pipline
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'pipline' to 'pipeline'.

Suggested change
// pipline
// pipeline

Copilot uses AI. Check for mistakes.
const pattern = `${prefix}${key}:*`;

let cursor = '0';
const batchSize = 1000; // SCAN 每次取多少
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 1000 for batch size should be extracted as a named constant at the module level. This would allow for consistent configuration across the codebase, as the same value is used in the cache module.

Copilot uses AI. Check for mistakes.
Comment on lines +29 to +30
const batchSize = 1000; // SCAN 每次取多少
const delChunk = 500; // 每次 pipeline 删除多少(可按需调)
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic numbers 1000 and 500 should be extracted as named constants at the module level. This would improve maintainability and make it easier to tune performance characteristics.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant