# Redis configuration for Ad-tlas application

# Network
bind 0.0.0.0
port 6379
protected-mode no

# General
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16

# Snapshotting
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data

# Replication
# replica-serve-stale-data yes
# replica-read-only yes

# Security
# requirepass your_redis_password_here
# rename-command FLUSHDB ""
# rename-command FLUSHALL ""
# rename-command DEBUG ""

# Memory management
maxmemory 256mb
maxmemory-policy allkeys-lru

# Append only file
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

# Slow log
slowlog-log-slower-than 10000
slowlog-max-len 128

# Latency monitor
latency-monitor-threshold 100

# Event notification
notify-keyspace-events ""

# Advanced config
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100

# Active rehashing
activerehashing yes

# Client output buffer limits
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

# Client query buffer limit
client-query-buffer-limit 1gb

# Protocol max bulk length
proto-max-bulk-len 512mb

# Hz
hz 10

# Dynamic HZ
dynamic-hz yes

# AOF rewrite incremental fsync
aof-rewrite-incremental-fsync yes

# RDB save incremental fsync
rdb-save-incremental-fsync yes

# LFU and LRU
lfu-log-factor 10
lfu-decay-time 1

# Threaded I/O
# io-threads 4
# io-threads-do-reads yes

# TLS/SSL (uncomment and configure if needed)
# port 0
# tls-port 6380
# tls-cert-file redis.crt
# tls-key-file redis.key
# tls-ca-cert-file ca.crt

# Modules (uncomment if using Redis modules)
# loadmodule /path/to/module.so

# Sentinel (uncomment if using Redis Sentinel)
# sentinel announce-ip <ip>
# sentinel announce-port <port>

# Cluster (uncomment if using Redis Cluster)
# cluster-enabled yes
# cluster-config-file nodes-6379.conf
# cluster-node-timeout 15000

# Memory usage optimization
tcp-keepalive 300
tcp-backlog 511
timeout 0

# Disable dangerous commands in production
# rename-command EVAL ""
# rename-command SCRIPT ""

# Enable keyspace notifications for Django cache
notify-keyspace-events "Ex"

# Optimize for Django sessions and cache
maxmemory-samples 5

# Log queries slower than 10ms
slowlog-log-slower-than 10000

# Increase client timeout for long-running operations
timeout 300

# Optimize TCP settings
tcp-keepalive 60

# Enable lazy freeing for better performance
lazyfree-lazy-eviction yes
lazyfree-lazy-expire yes
lazyfree-lazy-server-del yes
replica-lazy-flush yes

# Jemalloc background thread
jemalloc-bg-thread yes

# Disable RDB saves in development (uncomment for dev)
# save ""

# Enable protected mode in production
# protected-mode yes

# Set a password in production
# requirepass your_secure_redis_password_here