feat: 重构项目心跳数据结构并实现项目列表API
- 新增统一项目列表Redis键和迁移工具 - 实现GET /api/projects端点获取项目列表 - 实现POST /api/projects/migrate端点支持数据迁移 - 更新前端ProjectSelector组件使用真实项目数据 - 扩展projectStore状态管理 - 更新相关文档和OpenSpec规范 - 添加测试用例验证新功能
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
# Redis Connection Capability Design
|
||||
|
||||
## Context
|
||||
|
||||
This design document describes the technical implementation of the Redis connection capability for the BLS Project Console, which manages the connection between the system and the Redis server for reading logs and sending commands.
|
||||
|
||||
## Goals / Non-Goals
|
||||
|
||||
### Goals
|
||||
|
||||
- Establish and manage connection to Redis server
|
||||
- Provide configuration options for Redis connection
|
||||
- Implement automatic reconnection mechanism
|
||||
@@ -13,6 +15,7 @@ This design document describes the technical implementation of the Redis connect
|
||||
- Monitor and report connection status
|
||||
|
||||
### Non-Goals
|
||||
|
||||
- Redis server administration
|
||||
- Redis cluster management
|
||||
- Advanced Redis features (e.g., pub/sub, streams) beyond basic queue operations
|
||||
@@ -20,29 +23,33 @@ This design document describes the technical implementation of the Redis connect
|
||||
## Decisions
|
||||
|
||||
### Decision: Redis Client Library
|
||||
|
||||
- **What**: Use the official `redis` npm package
|
||||
- **Why**: It's the official Redis client for Node.js, well-maintained, and supports all Redis commands
|
||||
- **Alternatives considered**:
|
||||
- **Alternatives considered**:
|
||||
- `ioredis`: More features but more complex
|
||||
- `node-redis`: Older, less maintained
|
||||
|
||||
### Decision: Connection Configuration
|
||||
|
||||
- **What**: Use environment variables for Redis connection configuration
|
||||
- **Why**: Environment variables are a standard way to configure services in containerized environments, and they allow easy configuration without code changes
|
||||
- **Alternatives considered**:
|
||||
- **Alternatives considered**:
|
||||
- Configuration files: Less flexible for containerized environments
|
||||
- Hardcoded values: Not suitable for production use
|
||||
|
||||
### Decision: Reconnection Strategy
|
||||
|
||||
- **What**: Use exponential backoff for reconnection attempts
|
||||
- **Why**: Exponential backoff prevents overwhelming the Redis server with reconnection attempts, while still ensuring timely reconnection
|
||||
- **Alternatives considered**:
|
||||
- **Alternatives considered**:
|
||||
- Fixed interval reconnection: Less efficient, could overwhelm the server
|
||||
- No reconnection: Not suitable for production use
|
||||
|
||||
## Architecture
|
||||
|
||||
### Redis Connection Architecture
|
||||
|
||||
```
|
||||
Redis Connection Manager
|
||||
├── Redis Client
|
||||
@@ -54,25 +61,28 @@ Redis Connection Manager
|
||||
## Implementation Details
|
||||
|
||||
### Redis Client Initialization
|
||||
|
||||
1. Server reads Redis configuration from environment variables
|
||||
2. Server creates a Redis client instance with the configuration
|
||||
3. Server attaches event listeners for connection events (connect, error, end, reconnecting)
|
||||
4. Server attempts to connect to Redis
|
||||
|
||||
### Configuration Parameters
|
||||
| Parameter | Default Value | Environment Variable | Description |
|
||||
|-----------|---------------|----------------------|-------------|
|
||||
| host | localhost | REDIS_HOST | Redis server hostname |
|
||||
| port | 6379 | REDIS_PORT | Redis server port |
|
||||
| password | null | REDIS_PASSWORD | Redis server password |
|
||||
| db | 0 | REDIS_DB | Redis database index |
|
||||
| connectTimeout | 10000 | REDIS_CONNECT_TIMEOUT | Connection timeout in milliseconds |
|
||||
| maxRetriesPerRequest | 3 | REDIS_MAX_RETRIES | Maximum retries per request |
|
||||
| reconnectStrategy | exponential | REDIS_RECONNECT_STRATEGY | Reconnection strategy (exponential, fixed) |
|
||||
| reconnectInterval | 1000 | REDIS_RECONNECT_INTERVAL | Base reconnection interval in milliseconds |
|
||||
| maxReconnectInterval | 30000 | REDIS_MAX_RECONNECT_INTERVAL | Maximum reconnection interval in milliseconds |
|
||||
|
||||
| Parameter | Default Value | Environment Variable | Description |
|
||||
| -------------------- | ------------- | ---------------------------- | --------------------------------------------- |
|
||||
| host | localhost | REDIS_HOST | Redis server hostname |
|
||||
| port | 6379 | REDIS_PORT | Redis server port |
|
||||
| password | null | REDIS_PASSWORD | Redis server password |
|
||||
| db | 0 | REDIS_DB | Redis database index |
|
||||
| connectTimeout | 10000 | REDIS_CONNECT_TIMEOUT | Connection timeout in milliseconds |
|
||||
| maxRetriesPerRequest | 3 | REDIS_MAX_RETRIES | Maximum retries per request |
|
||||
| reconnectStrategy | exponential | REDIS_RECONNECT_STRATEGY | Reconnection strategy (exponential, fixed) |
|
||||
| reconnectInterval | 1000 | REDIS_RECONNECT_INTERVAL | Base reconnection interval in milliseconds |
|
||||
| maxReconnectInterval | 30000 | REDIS_MAX_RECONNECT_INTERVAL | Maximum reconnection interval in milliseconds |
|
||||
|
||||
### Reconnection Implementation
|
||||
|
||||
- Use the built-in reconnection feature of the `redis` package
|
||||
- Configure exponential backoff with:
|
||||
- Initial delay: 1 second
|
||||
@@ -81,11 +91,13 @@ Redis Connection Manager
|
||||
- Log each reconnection attempt with timestamp and delay
|
||||
|
||||
### Error Handling
|
||||
|
||||
- **Connection errors**: Log the error, update connection status, and attempt to reconnect
|
||||
- **Command errors**: Log the error, update the command status, and notify the user
|
||||
- **Timeout errors**: Log the error, update connection status, and attempt to reconnect
|
||||
|
||||
### Connection Monitoring
|
||||
|
||||
- Track connection status (connecting, connected, disconnected, error)
|
||||
- Log status changes with timestamps
|
||||
- Expose connection status via API endpoint
|
||||
@@ -94,21 +106,26 @@ Redis Connection Manager
|
||||
## Risks / Trade-offs
|
||||
|
||||
### Risk: Redis Server Unavailability
|
||||
|
||||
- **Risk**: If the Redis server is unavailable for an extended period, the system won't be able to read logs or send commands
|
||||
- **Mitigation**: Implement proper error handling and reconnection logic, and notify users of the issue
|
||||
|
||||
### Risk: Misconfiguration of Redis Connection
|
||||
|
||||
- **Risk**: Incorrect Redis configuration could lead to connection failures
|
||||
- **Mitigation**: Validate configuration on startup, log configuration values (excluding passwords), and provide clear error messages
|
||||
|
||||
### Risk: Performance Impact of Reconnection Attempts
|
||||
|
||||
- **Risk**: Frequent reconnection attempts could impact system performance
|
||||
- **Mitigation**: Use exponential backoff to reduce the frequency of reconnection attempts, and limit the maximum reconnection delay
|
||||
|
||||
## Migration Plan
|
||||
|
||||
No migration is required as this is a new feature.
|
||||
|
||||
## Open Questions
|
||||
|
||||
- What is the expected Redis server availability?
|
||||
- Should we implement connection pooling for better performance?
|
||||
- Should we support Redis Sentinel or Cluster for high availability?
|
||||
- Should we support Redis Sentinel or Cluster for high availability?
|
||||
|
||||
Reference in New Issue
Block a user