Deployment
Guides for deploying ACOR in various environments.
Architecture Overview
graph TB
subgraph Application
A[ACOR Client]
end
subgraph Redis
B[(Standalone)]
C[(Sentinel)]
D[(Cluster)]
end
A --> B
A --> C
A --> D
Standalone Deployment
Simplest deployment for development or small workloads:
ac, err := acor.Create(&acor.AhoCorasickArgs{
Addr: "redis:6379",
Password: os.Getenv("REDIS_PASSWORD"),
DB: 0,
Name: "production",
})
if err != nil {
panic(err)
}
High Availability with Sentinel
For production workloads requiring failover:
ac, err := acor.Create(&acor.AhoCorasickArgs{
Addrs: []string{
"sentinel-1:26379",
"sentinel-2:26379",
"sentinel-3:26379",
},
MasterName: "mymaster",
Password: os.Getenv("REDIS_PASSWORD"),
Name: "production",
})
if err != nil {
panic(err)
}
Cluster Deployment
For horizontal scaling:
ac, err := acor.Create(&acor.AhoCorasickArgs{
Addrs: []string{
"redis-node-1:7000",
"redis-node-2:7000",
"redis-node-3:7000",
},
Password: os.Getenv("REDIS_PASSWORD"),
Name: "production",
})
if err != nil {
panic(err)
}
Kubernetes Deployment
ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: acor-config
data:
REDIS_ADDR: "redis-service:6379"
ACOR_COLLECTION: "production"
Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: acor-app
spec:
replicas: 3
selector:
matchLabels:
app: acor-app
template:
metadata:
labels:
app: acor-app
spec:
containers:
- name: app
image: myapp:latest
envFrom:
- configMapRef:
name: acor-config
Docker Compose
version: "3.8"
services:
redis:
image: redis:7-alpine
ports:
- "6379:6379"
app:
build: .
depends_on:
- redis
environment:
- REDIS_ADDR=redis:6379
Health Checks
ACOR provides health check endpoints:
import "github.com/skyoo2003/acor/pkg/health"
handler := health.NewHandler(ac)
http.Handle("/healthz", handler.Livez())
http.Handle("/readyz", handler.Readyz())
Best Practices
- Use connection pooling (built-in)
- Set appropriate timeouts
- Monitor Redis memory usage
- Use V2 schema for new collections
- Implement graceful shutdown