Skip to content

Commit 16afa00

Browse files
author
petethepossum
committed
Added daily reward logic and redis health status tracking.
Also added chatsnap functionaility to record chat messages Also MAJOR improvements to /profile
1 parent 9279eb1 commit 16afa00

File tree

27 files changed

+1131
-345
lines changed

27 files changed

+1131
-345
lines changed

REDIS_IMPROVEMENTS.md

Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,306 @@
1+
# Redis Status Tracking Improvements
2+
3+
This document outlines the improvements made to the Redis status tracking system in your Alchemist plugin.
4+
5+
## Overview
6+
7+
The Redis implementation has been significantly enhanced with:
8+
- **Health Monitoring**: Continuous connection health checks
9+
- **Automatic Reconnection**: Self-healing connection management
10+
- **Better Error Handling**: Comprehensive exception handling with retry logic
11+
- **Performance Optimization**: Connection pooling and batch operations
12+
- **Administrative Tools**: Commands for monitoring and managing Redis
13+
14+
## Configuration
15+
16+
**Important**: This system works with your existing Redis configuration in `config.yml`. No changes to your current Redis settings are required!
17+
18+
### Your Existing Redis Configuration (Required)
19+
20+
```yaml
21+
redis:
22+
host: "127.0.0.1"
23+
port: 6379
24+
username: ""
25+
password: ""
26+
```
27+
28+
### Optional Advanced Configuration
29+
30+
You can optionally add advanced settings to your existing Redis section:
31+
32+
```yaml
33+
redis:
34+
host: "127.0.0.1"
35+
port: 6379
36+
username: ""
37+
password: ""
38+
# Advanced Redis configuration (optional)
39+
advanced:
40+
# Connection pool settings
41+
maxTotalConnections: 20
42+
maxIdleConnections: 10
43+
minIdleConnections: 2
44+
connectionTimeout: 2000
45+
maxWaitTime: 5000
46+
47+
# Health monitoring settings
48+
healthCheckInterval: 30
49+
maxReconnectAttempts: 5
50+
slowQueryThreshold: 1000
51+
52+
# Retry settings
53+
maxRetries: 3
54+
retryBackoffMultiplier: 1000
55+
56+
# TTL settings (in seconds)
57+
onlineStatusTTL: 60
58+
vanishStatusTTL: 0
59+
```
60+
61+
**Note**: If you don't add the `advanced` section, the system will use sensible defaults that work well for most servers.
62+
63+
## New Features
64+
65+
### 1. Redis Health Monitor (`RedisHealthMonitor`)
66+
67+
**Location**: `commons/src/main/kotlin/ltd/matrixstudios/alchemist/redis/RedisHealthMonitor.kt`
68+
69+
- **Automatic Health Checks**: Runs every 30 seconds by default (configurable)
70+
- **Connection Pool Optimization**: Uses your Redis connection settings
71+
- **Failure Tracking**: Monitors connection failures and attempts reconnection
72+
- **Performance Monitoring**: Tracks response times and alerts on slow queries
73+
74+
### 2. Enhanced Redis Packet Manager (`RedisPacketManager`)
75+
76+
**Location**: `commons/src/main/kotlin/ltd/matrixstudios/alchemist/redis/RedisPacketManager.kt`
77+
78+
- **Retry Mechanism**: Automatic retry with exponential backoff (configurable)
79+
- **Connection Testing**: Validates connections on startup
80+
- **Health Status**: Provides real-time connection health information
81+
- **Graceful Shutdown**: Proper cleanup of resources
82+
83+
### 3. Improved Online Status Service (`RedisOnlineStatusService`)
84+
85+
**Location**: `commons/src/main/kotlin/ltd/matrixstudios/alchemist/redis/RedisOnlineStatusService.kt`
86+
87+
- **Async Operations**: Non-blocking Redis operations
88+
- **Batch Processing**: Efficient handling of multiple operations
89+
- **Fallback Handling**: Graceful degradation when Redis is unavailable
90+
- **Performance Metrics**: Connection pool utilization tracking
91+
92+
### 4. Redis Configuration (`RedisConfig`)
93+
94+
**Location**: `commons/src/main/kotlin/ltd/matrixstudios/alchemist/redis/RedisConfig.kt`
95+
96+
- **Reads Your Existing Config**: Automatically loads from your `config.yml`
97+
- **Sensible Defaults**: Works even without advanced configuration
98+
- **Validation**: Configuration error checking
99+
- **Centralized Settings**: All Redis settings in one place
100+
101+
## Commands
102+
103+
### Redis Command (`/redis`)
104+
105+
**Permission**: `alchemist.owner`
106+
107+
Provides basic Redis information:
108+
- Connection status
109+
- Packet statistics
110+
- Online player count
111+
- Server information
112+
113+
### Redis Status Command (`/redisstatus`)
114+
115+
**Permission**: `alchemist.admin`
116+
117+
#### Subcommands:
118+
119+
- **`/redisstatus info`** - Detailed connection and configuration information
120+
- **`/redisstatus health`** - Real-time health check with operation testing
121+
- **`/redisstatus reconnect`** - Force reconnection attempt
122+
- **`/redisstatus stats`** - Connection pool utilization and statistics
123+
124+
## Health Monitoring
125+
126+
### Automatic Health Checks
127+
128+
The system automatically:
129+
- Pings Redis every 30 seconds (configurable via `healthCheckInterval`)
130+
- Tracks response times
131+
- Monitors connection pool utilization
132+
- Attempts automatic reconnection on failures
133+
134+
### Health Status Indicators
135+
136+
- **Healthy**: Redis is responding normally
137+
- **Unhealthy**: Connection issues detected
138+
- **Connection Failures**: Number of failed connection attempts
139+
140+
### Performance Alerts
141+
142+
- **Slow Query Warning**: Alerts when response time exceeds threshold
143+
- **High Pool Utilization**: Warns when connection pool is heavily used
144+
- **Connection Failures**: Tracks and reports connection issues
145+
146+
## Error Handling
147+
148+
### Retry Mechanism
149+
150+
- **Automatic Retries**: Up to 3 attempts by default (configurable via `maxRetries`)
151+
- **Exponential Backoff**: Increasing delays between retry attempts
152+
- **Connection Exception Handling**: Specific handling for connection issues
153+
- **Graceful Degradation**: Fallback behavior when Redis is unavailable
154+
155+
### Exception Types
156+
157+
- **JedisConnectionException**: Network or connection issues
158+
- **JedisException**: Redis-specific errors
159+
- **General Exceptions**: Other runtime errors
160+
161+
## Performance Optimizations
162+
163+
### Connection Pooling
164+
165+
- **Optimized Pool Settings**: Uses your Redis connection settings
166+
- **Connection Testing**: Validates connections before use
167+
- **Resource Management**: Proper cleanup and resource handling
168+
169+
### Batch Operations
170+
171+
- **Pipeline Support**: Efficient handling of multiple Redis operations
172+
- **Async Operations**: Non-blocking Redis calls
173+
- **Connection Reuse**: Minimizes connection overhead
174+
175+
## Monitoring and Debugging
176+
177+
### Console Logging
178+
179+
The system provides detailed console logging:
180+
- Connection status changes
181+
- Health check results
182+
- Performance warnings
183+
- Error details
184+
185+
### Metrics Available
186+
187+
- Connection pool statistics
188+
- Health check timing
189+
- Failure counts
190+
- Response times
191+
- Pool utilization
192+
193+
## Best Practices
194+
195+
### 1. Configuration
196+
197+
- Your existing Redis configuration will work immediately
198+
- Add advanced settings only if you need to tune performance
199+
- Use health monitoring for production environments
200+
201+
### 2. Monitoring
202+
203+
- Regularly check `/redisstatus health`
204+
- Monitor console logs for warnings
205+
- Set up alerts for connection failures
206+
207+
### 3. Performance
208+
209+
- Use batch operations when possible
210+
- Monitor connection pool utilization
211+
- Adjust pool settings based on usage patterns
212+
213+
## Troubleshooting
214+
215+
### Common Issues
216+
217+
1. **Connection Refused**
218+
- Check Redis server status
219+
- Verify your existing host/port configuration
220+
- Check firewall settings
221+
222+
2. **Slow Response Times**
223+
- Monitor Redis server performance
224+
- Check network latency
225+
- Review connection pool settings
226+
227+
3. **High Failure Rates**
228+
- Check Redis server logs
229+
- Verify your existing authentication credentials
230+
- Monitor server resources
231+
232+
### Debug Commands
233+
234+
- `/redis` - Basic status information
235+
- `/redisstatus health` - Detailed health check
236+
- `/redisstatus stats` - Performance metrics
237+
238+
## Migration Notes
239+
240+
### Existing Code Compatibility
241+
242+
- **100% Backward Compatible**: All existing Redis operations continue to work
243+
- **No Config Changes Required**: Works with your current `config.yml`
244+
- **New Features Are Optional**: Advanced settings are completely optional
245+
- **Performance Impact**: Minimal overhead from health monitoring
246+
247+
### What Happens on Startup
248+
249+
1. System reads your existing Redis configuration
250+
2. Applies sensible defaults for any missing advanced settings
251+
3. Starts health monitoring automatically
252+
4. Logs the configuration being used
253+
254+
## Support
255+
256+
For issues or questions about the Redis improvements:
257+
1. Check the console logs for error messages
258+
2. Use the diagnostic commands (`/redisstatus`)
259+
3. Verify your existing Redis configuration
260+
4. Check Redis server status and logs
261+
262+
## Quick Start
263+
264+
1. **No configuration changes needed** - the system works with your existing Redis setup
265+
2. Restart your server
266+
3. Use `/redis` to see basic status
267+
4. Use `/redis health` for quick health check
268+
5. Use `/redisstatus health` for detailed health information
269+
6. Monitor console logs for health monitoring messages
270+
271+
## Technical Details
272+
273+
### Platform-Agnostic Design
274+
275+
The Redis improvements are designed with a clean separation of concerns:
276+
277+
- **Commons Module** - Pure Kotlin/Java with no platform dependencies
278+
- Uses standard `println()` for logging
279+
- Standard Java logging (`Logger`) for warnings
280+
- No imports of Spigot, Bungee, or Velocity APIs
281+
- Works on any Java/Kotlin platform
282+
283+
- **Platform Plugins** - Handle platform-specific functionality
284+
- Spigot: Chat commands, colored console messages, health check triggers
285+
- Bungee: Basic Redis configuration loading
286+
- Velocity: Basic Redis configuration loading
287+
288+
### Configuration Loading Flow
289+
290+
```
291+
config.yml → Platform Plugin → RedisConfig.loadBasicConfig() → Redis Services
292+
293+
Advanced Section → RedisConfig.loadAdvancedConfig() → Enhanced Settings
294+
```
295+
296+
### Dependencies
297+
298+
- **Commons Module**: No external dependencies, pure Kotlin
299+
- **Platform Plugins**: Use their native configuration systems
300+
- **Redis Services**: All use the centralized RedisConfig object
301+
302+
### Platform Support
303+
304+
- **Spigot**: Full support with advanced configuration options and admin commands
305+
- **Bungee**: Full support with basic configuration
306+
- **Velocity**: Full support with basic configuration
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ltd.matrixstudios.alchemist.models.chatsnap
2+
3+
import java.util.UUID
4+
5+
data class ChatSnap(
6+
var id: UUID,
7+
var owner: UUID,
8+
var messages: List<String>,
9+
var createdAt: Long,
10+
var numericId: Int = 0
11+
)

commons/src/main/kotlin/ltd/matrixstudios/alchemist/models/filter/Filter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ data class Filter(
1212
var staffExempt: Boolean,
1313
var exemptPermission: String,
1414
var shouldPunish: Boolean,
15+
var numericId: Int = 0
1516
) {
1617

1718
}

0 commit comments

Comments
 (0)