Bugfixes, add INFO command, graceful shutdown. elimitate dead code

- Remove unsed handleClientKill, handleClientKill
- Fix misleading error message on rate limit
- Eliminated unused channel-to-pattern index that was causing unnecessary work
- Fixed O(n²) duplicate check in PublishToPattern
- Limit total pattern subscriptions to 10,000
- Limit channel subscriptions per client to 10,000
- Added INFO command
- Added graceful shutdown timeout
- Validate that log directory is writable during config load
- Make SELECT properly handle whitespace around DB index like Redis
- Return proper error instead of empty array for unsupported commands on sharded pubsub stubs
- More accurate error messages throughout
- Updated README.md
This commit is contained in:
eleksir
2026-04-03 10:01:29 +03:00
parent 92cd652b0d
commit 488ce1e4d1
9 changed files with 321 additions and 115 deletions

View File

@@ -17,7 +17,8 @@ A lightweight, focused Pub/Sub message broker that provides core Redis pub/sub c
5. **Graceful shutdown** - Signal handling for clean server termination (SIGINT, SIGTERM)
6. **Log re-opening** - SIGUSR1 (Unix) or SIGHUP (Windows) for log rotation support
7. **Case-insensitive commands** - Commands are case-insensitive per Redis specification
8. **CLIENT command support** - Minimal CLIENT command for client library compatibility
9. **INFO command** - Full Redis-compatible INFO output for client compatibility
10. **Graceful shutdown timeout** - Configurable timeout to prevent server hanging on misbehaving clients
## Fundamental Rules
@@ -120,9 +121,12 @@ Test scenarios include:
- Basic SUBSCRIBE/PUBLISH/UNSUBSCRIBE
- Pattern PSUBSCRIBE/PUNSUBSCRIBE with wildcards
- Multiple channel/pattern subscriptions
- PUBSUB NUMSUB, CHANNELS, NUMPAT commands
- PUBSUB NUMSUB, CHANNELS, NUMPAT, SHARDCHANNELS, SHARDNUMSUB commands
- PING command (with and without message)
- QUIT command
- SELECT database switching (for client compatibility)
- INFO server information (full Redis-compatible output)
- CLIENT ID, SETNAME, GETNAME, LIST, INFO, KILL, PAUSE, UNPAUSE, REPLY commands
- Binary-safe messages
- Empty and long messages
- Unicode content
@@ -137,9 +141,11 @@ Test scenarios include:
- PSUBSCRIBE - Subscribe to patterns
- PUNSUBSCRIBE - Unsubscribe from patterns
- PUBLISH - Publish message to channel
- PUBSUB - Pub/Sub introspection (NUMSUB, CHANNELS, NUMPAT, HELP)
- PUBSUB - Pub/Sub introspection (NUMSUB, CHANNELS, NUMPAT, SHARDCHANNELS, SHARDNUMSUB, HELP)
- PING - Health check
- QUIT - Disconnect
- SELECT - Switch database (for client compatibility, no-op in pekoe)
- INFO - Server information
- CLIENT - Connection introspection and control:
- CLIENT ID - Return unique connection ID
- CLIENT SETNAME/GETNAME - Connection naming
@@ -178,4 +184,20 @@ When `pid_file` is configured, pekoe will:
- Remove the PID file on graceful shutdown
- Log PID file events (created, removed, errors)
The PID file is optional - if `pid_file` is empty, no PID file is created.
The PID file is optional - if `pid_file` is empty, no PID file is created.
## Graceful Shutdown Timeout
When receiving shutdown signal (SIGINT/SIGTERM), pekoe waits for active connections to finish before exiting. The `shutdown_timeout` config option (default: 30 seconds) controls how long to wait:
- If all connections close within the timeout, shutdown completes normally
- If timeout expires, server exits forcefully (active connections are lost)
Set to 0 to wait forever (not recommended - server may hang on misbehaving clients).
## Run ID
Each server instance generates a unique 40-character hexadecimal run ID on startup (like Redis). This ID is:
- Displayed in INFO output as `run_id`
- Useful for distinguishing between server restarts in logs
- Generated using 160 bits of cryptographic randomness