Redis Service Documentation
Overview
The Redis service provides a robust, type-safe interface for interacting with Redis in the Gradiant application. It includes connection pooling, automatic reconnection, health monitoring, and comprehensive error handling.Installation
Configuration
The Redis service can be configured using theRedisServiceConfig interface:
Default Configuration
Basic Usage
Initialization
Key-Value Operations
Set Operations
Counter Operations
Health Checks
Error Handling
The service uses a customRedisServiceError class with specific error codes:
Best Practices
-
Connection Management
- Always call
connect()before using the service - Call
disconnect()when shutting down the application - Use the health check mechanism to monitor connection status
- Always call
-
Error Handling
- Catch and handle
RedisServiceErrorspecifically - Log errors with appropriate context
- Implement retry logic for transient failures
- Catch and handle
-
Performance Optimization
- Use appropriate TTLs for cached data
- Batch operations when possible
- Monitor connection pool statistics
-
Security
- Use environment variables for Redis URL
- Implement proper access controls
- Sanitize data before storage
Environment Variables
Required environment variables:Integration with Other Services
Cache Invalidation
Analytics Service
Pattern Recognition Service
Testing
The service includes comprehensive test suites:-
Unit Tests
-
Integration Tests
-
Performance Tests
Monitoring and Metrics
The service provides built-in monitoring capabilities through thegetPoolStats() method:
Troubleshooting
Common issues and solutions:-
Connection Failures
- Check Redis URL configuration
- Verify network connectivity
- Check Redis server status
- Review connection pool settings
-
Performance Issues
- Monitor connection pool statistics
- Check for connection leaks
- Review operation patterns
- Consider Redis configuration
-
Memory Issues
- Implement proper TTLs
- Monitor Redis memory usage
- Review key patterns and data size
- Consider Redis persistence settings