Redis Testing

Comprehensive Redis integration testing guide

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:

  1. Basic Operation Test

    • Verify GET/SET functionality
    • Test data persistence
  2. Custom Domain Caching

    • Test domain mapping storage
    • Verify lookup performance
  3. Large Value Handling

    • Test binary data support
    • Verify size limits
  4. Concurrent Access Patterns

    • Multiple simultaneous requests
    • Connection pool efficiency
  5. TTL Expiration

    • Verify automatic expiration
    • Test cache refresh
  6. Connection Pool Verification

    • Monitor pool utilisation
    • Test pool limits
  7. 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:

  1. Verify Redis is running: redis-cli PING
  2. Check hostname and port settings
  3. Verify firewall rules
  4. Check network connectivity

Authentication Problems

Symptoms:

  • Authentication failed errors
  • Access denied messages

Solutions:

  1. Verify password is correct
  2. Check Redis configuration: redis-cli CONFIG GET requirepass
  3. Test authentication: redis-cli -a password PING

Performance Degradation

Symptoms:

  • Slow response times
  • Timeout errors

Solutions:

  1. Check Redis memory usage
  2. Monitor connection pool utilisation
  3. Verify network latency
  4. Review key expiration settings

Connection Pool Exhaustion

Symptoms:

  • Connection pool full errors
  • Request queuing

Solutions:

  1. Increase pool size in configuration
  2. Review connection leak scenarios
  3. Monitor active connections
  4. Implement connection timeouts

Best Practices

  1. Use Connection Pooling - Efficient resource management
  2. Monitor Performance - Track metrics regularly
  3. Implement Backups - Protect cache data
  4. Use TTL Appropriately - Balance freshness vs. load
  5. Test Failover - Verify fallback behaviour
  6. 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