The official high-performance Redis provider for Argus. Provides real-time configuration loading, live watching capabilities, and professional-grade security features for production environments.
Features • Installation • Quick Start • Advanced Configuration • Security Features • Performance • Monitoring
High Performance
- Pre-compiled security patterns for zero-allocation validation
- Efficient connection pooling with configurable limits
- Atomic counters for real-time metrics
- Optimized watch mechanism using Redis pub/sub
Securite by Design
- Red-team tested
- Redis injection prevention
- Forbidden command detection
- URL validation and normalization
- Response size limits (DoS protection)
- Concurrent request limits
Redis Support
- Standalone Redis servers
- Redis Cluster mode
- Redis Sentinel
- Unix socket connections
- TLS/SSL encrypted connections
- Authentication support
Monitoring & Observability
- Real-time performance metrics
- Health check endpoints
- Connection status monitoring
- Request/error counters
argus-provider-redis is designed to work with Redis 9+ and follows Long-Term Support guidelines to ensure consistent performance across production deployments.
go get github.com/agilira/argus-provider-redis
package main
import (
"fmt"
"log"
"time"
redis "github.com/agilira/argus-provider-redis"
)
func main() {
// Create provider
provider, err := redis.NewProvider("redis://localhost:6379")
if err != nil {
log.Fatal(err)
}
defer provider.Close()
// Load configuration
value, err := provider.Load("app-config")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Config: %v\n", value)
// Watch for changes
err = provider.Watch("app-config", func(newValue interface{}) {
fmt.Printf("Config updated: %v\n", newValue)
})
if err != nil {
log.Fatal(err)
}
}
provider, err := redis.NewProvider("redis://localhost:6379",
redis.WithPassword("secure-password"),
redis.WithDatabase(1),
redis.WithTimeout(15*time.Second),
redis.WithMaxRetries(5),
redis.WithPoolSize(20),
)
tlsConfig := &tls.Config{
ServerName: "redis.example.com",
MinVersion: tls.VersionTLS12,
}
provider, err := redis.NewProvider("rediss://redis.example.com:6380",
redis.WithTLS(tlsConfig),
)
provider, err := redis.NewProvider("redis://node1:6379,node2:6379,node3:6379")
// Get real-time statistics
stats := provider.GetStats()
fmt.Printf("Active requests: %v\n", stats["active_requests"])
fmt.Printf("Total errors: %v\n", stats["total_errors"])
fmt.Printf("Active watches: %v\n", stats["active_watches"])
// Health check
if err := provider.HealthCheck(); err != nil {
log.Printf("Redis health check failed: %v", err)
}
- Prevents Redis injection attacks
- Validates key length and patterns
- Blocks dangerous command injection
- URL validation and normalization
- Host validation with security checks
- Path traversal prevention
- Maximum response size limits (50MB)
- Concurrent request limits (100 per instance)
- Active watch limits (20 per instance)
- Request timeout handling
// Zero-allocation security pattern matching
var dangerousKeyPatterns = []string{
"__", "..", "//", "\\", "*", "?", "[", "]",
"{", "}", "|", "<", ">", ":", ";", "'", "\"",
}
// Atomic counters for thread-safe metrics
atomic.AddInt64(&p.activeRequests, 1)
atomic.AddInt64(&p.totalRequests, 1)
- Configurable pool size (default: 10)
- Connection reuse and management
- Automatic reconnection handling
The provider uses structured errors with context:
// 404 for missing keys
value, err := provider.Load("nonexistent-key")
// err will have code 404
// Security validation errors
err := provider.Load("../dangerous-key")
// err: "Redis key contains dangerous pattern: .."
// Network timeouts
err := provider.Load("slow-key")
// err: wrapped timeout error with context
Performance benchmarks show significant optimizations:
BenchmarkLoad-8 1000000 1205 ns/op 224 B/op 4 allocs/op
BenchmarkValidateKey-8 10000000 156 ns/op 0 B/op 0 allocs/op
BenchmarkWatch-8 500000 2890 ns/op 512 B/op 8 allocs/op
Option | Default | Description |
---|---|---|
WithPassword(string) |
"" | Redis authentication password |
WithDatabase(int) |
0 | Redis database number (0-15) |
WithTimeout(duration) |
10s | Operation timeout |
WithMaxRetries(int) |
3 | Maximum retry attempts |
WithPoolSize(int) |
10 | Connection pool size |
WithTLS(*tls.Config) |
nil | TLS configuration |
Supported Redis connection URLs:
redis://localhost:6379
- Standard connectionrediss://localhost:6380
- TLS/SSL connectionredis://user:pass@localhost:6379/1
- With authentication and databaseredis://node1:6379,node2:6379,node3:6379
- Cluster modeunix:///tmp/redis.sock
- Unix socket
Mozilla Public License 2.0 - see the LICENSE file for details.
argus-provider-redis • an AGILira library