Redis Testing
The pages-server Traefik plugin includes a complete Redis client implementation using only Go standard library packages, making it compatible with Traefik’s Yaegi interpreter.
Overview
The system supports GET, SET, SETEX, DEL, and FLUSHDB commands with automatic fallback to in-memory caching if Redis becomes unavailable.
Setup Options
Five installation methods are documented:
Docker
docker run -d -p 6379:6379 redis:latest
Podman
podman run -d -p 6379:6379 redis:latest
Valkey (Redis Fork)
# Installation instructions for Valkey
Homebrew (macOS)
brew install redis
brew services start redis
APT (Ubuntu/Debian)
sudo apt-get update
sudo apt-get install redis-server
sudo systemctl start redis-server
Testing Approaches
Automated Tests
Run comprehensive test suites using Go’s testing framework:
Run All Tests:
go test -v
Run Redis-Specific Tests:
go test -v -run Redis
Run Individual Test Cases:
go test -v -run TestRedisCache_GetSet
Test Coverage:
- GET/SET operations
- TTL expiration
- Connection pooling
- Binary data handling
- Error scenarios
Manual Integration Testing
Seven manual test scenarios verify plugin-to-Redis interoperability:
-
Basic Operation Test
- Verify GET/SET functionality
- Test data persistence
-
Custom Domain Caching
- Test domain mapping storage
- Verify lookup performance
-
Large Value Handling
- Test binary data support
- Verify size limits
-
Concurrent Access Patterns
- Multiple simultaneous requests
- Connection pool efficiency
-
TTL Expiration
- Verify automatic expiration
- Test cache refresh
-
Connection Pool Verification
- Monitor pool utilisation
- Test pool limits
-
Error Recovery
- Redis disconnect scenarios
- Fallback behaviour
Performance Testing
Benchmark tests target response times:
Target Metrics:
- Response Time: < 5ms overall
- GET/SET Operations: < 1ms ideal
- Connection Pool Access: < 0.1ms
Running Benchmarks:
go test -bench=. -benchmem
Authentication & Security
Password-Protected Redis
Configure authentication when necessary:
redis:
host: localhost
port: 6379
password: your-secure-password
Testing with Authentication:
redis-cli -a your-password PING
Production Monitoring
Connection Tracking
Monitor Redis connections:
redis-cli CLIENT LIST
Memory Usage
Check Redis memory consumption:
redis-cli INFO memory
Cache Hit Rates
Monitor cache effectiveness:
redis-cli INFO stats | grep keyspace
Integration with Traefik
Traefik middleware configuration:
http:
middlewares:
pages-server:
plugin:
pages-server:
redisHost: localhost
redisPort: 6379
redisPassword: optional-password
Troubleshooting
Connection Failures
Symptoms:
- Cannot connect to Redis
- Connection refused errors
Solutions:
- Verify Redis is running:
redis-cli PING - Check hostname and port settings
- Verify firewall rules
- Check network connectivity
Authentication Problems
Symptoms:
- Authentication failed errors
- Access denied messages
Solutions:
- Verify password is correct
- Check Redis configuration:
redis-cli CONFIG GET requirepass - Test authentication:
redis-cli -a password PING
Performance Degradation
Symptoms:
- Slow response times
- Timeout errors
Solutions:
- Check Redis memory usage
- Monitor connection pool utilisation
- Verify network latency
- Review key expiration settings
Connection Pool Exhaustion
Symptoms:
- Connection pool full errors
- Request queuing
Solutions:
- Increase pool size in configuration
- Review connection leak scenarios
- Monitor active connections
- Implement connection timeouts
Best Practices
- Use Connection Pooling - Efficient resource management
- Monitor Performance - Track metrics regularly
- Implement Backups - Protect cache data
- Use TTL Appropriately - Balance freshness vs. load
- Test Failover - Verify fallback behaviour
- Secure Credentials - Use authentication in production
Example Test Script
#!/bin/bash
# test_redis.sh
echo "Testing Redis connection..."
redis-cli PING
echo "Testing SET operation..."
redis-cli SET test:key "test-value"
echo "Testing GET operation..."
redis-cli GET test:key
echo "Testing TTL..."
redis-cli SETEX test:ttl 10 "expires-in-10s"
redis-cli TTL test:ttl
echo "Cleaning up..."
redis-cli DEL test:key test:ttl
echo "Tests complete!"
Integration Testing Checklist
- Redis service running
- Authentication configured (if needed)
- Connection pool sized appropriately
- TTL values configured
- Monitoring enabled
- Backup strategy in place
- Failover tested
- Performance benchmarks met