Avoid Common Pitfalls When Deploying Redis in Production: Memory, Persistence, and Clustering
This guide walks through practical Redis production‑deployment best practices, covering memory limits and eviction policies, RDB/AOF persistence options, security hardening, replication, Sentinel, Cluster setup, monitoring, backup scripts, and troubleshooting common issues such as OOM, replication loss, and latency.
1 Memory Configuration
1.1 Max Memory
# View current maxmemory
redis-cli CONFIG GET maxmemory
# Set maxmemory (bytes)
redis-cli CONFIG SET maxmemory 10737418240 # 10GB
# Temporary (lost after restart)
redis-server --maxmemory 10gb
# Permanent (redis.conf)
maxmemory 10gbMemory unit conversion :
1k → 1000 bytes
1kb → 1024 bytes
1m → 1000000 bytes
1mb → 1024*1024 bytes
1g → 1000000000 bytes
1gb → 1024*1024*1024 bytes
1.2 Eviction Policy
When memory reaches maxmemory, Redis evicts keys according to the configured policy.
# View current policy
redis-cli CONFIG GET maxmemory-policy
# Set policy
redis-cli CONFIG SET maxmemory-policy allkeys-lruAvailable policies :
noeviction : never evicts, returns an error – use when data loss is unacceptable.
allkeys-lru : evicts least‑recently‑used keys – suitable for generic cache workloads.
allkeys-lfu : evicts least‑frequently‑used keys – ideal for hot‑spot data.
allkeys-random : evicts random keys – for random‑eviction scenarios.
volatile-lru : evicts LRU among keys with a TTL – mixed cache/persistent data.
volatile-lfu : evicts LFU among keys with a TTL – mixed cache/persistent data.
volatile-random : evicts random keys with a TTL – mixed cache/persistent data.
volatile-ttl : evicts keys with the shortest TTL first – keeps hot data.
LRU vs LFU :
LRU (Least Recently Used) : removes the key that has not been accessed for the longest time.
LFU (Least Frequently Used) : removes the key with the lowest access frequency.
1.3 Memory Fragmentation
Redis uses glibc’s allocator, which can cause fragmentation.
# Check fragmentation ratio
redis-cli INFO memory | grep mem_fragmentation_ratio
# Manual defragmentation (Redis 4.0+)
redis-cli MEMORY PURGE
# Restart also clears fragmentationFragmentation ratio interpretation :
1.0 ~ 1.5 – normal.
≈ 1.5 – high fragmentation, consider defragmentation.
<1.0 – swapping or insufficient physical memory.
1.4 Reducing Fragmentation
Use jemalloc (default allocator).
Set a reasonable maxmemory to avoid frequent evictions.
Enable active defragmentation on Redis 4.0+.
# Enable active defragmentation
redis-cli CONFIG SET activedefrag yes
# Verify stats
redis-cli INFO memory | grep mem_fragmentation_ratio1.5 Memory Monitoring
# Detailed memory info
redis-cli INFO memory
# Sample output (excerpt)
# used_memory: 1073741824 # actual memory used by Redis
# used_memory_human: 1.00G
# used_memory_rss: 1258291200 # OS‑allocated physical memory
# used_memory_rss_human: 1.17G
# used_memory_peak: 2147483648 # peak usage
# mem_fragmentation_ratio: 1.17
# mem_allocator: jemalloc-5.2.1
# Simple monitoring script (bash)
#!/bin/bash
USED=$(redis-cli INFO memory | grep used_memory | awk -F: '{print $2}')
PEAK=$(redis-cli INFO memory | grep used_memory_peak | awk -F: '{print $2}')
MAX=$(redis-cli CONFIG GET maxmemory | tail -1)
echo "Used: $((USED/1024/1024)) MB"
echo "Peak: $((PEAK/1024/1024)) MB"
echo "Max: $((MAX/1024/1024)) MB"
echo "Usage: $(echo "scale=2; $USED*100/$MAX" | bc)%"2 Persistence Configuration
2.1 RDB (Snapshot) Persistence
RDB creates compact binary snapshots at configured intervals.
# Trigger manually
redis-cli BGSAVE
# Or synchronous save (blocks Redis)
redis-cli SAVE
# Check last save time
redis-cli DEBUG SLEEP 1 && redis-cli LASTSAVE
# View persistence info
redis-cli INFO persistence
# Example fields:
# rdb_changes_since_last_save: 0
# rdb_last_save_time: 1609459200
# rdb_last_bgsave_status: ok
# rdb_last_bgsave_time_sec: 1RDB settings (redis.conf) :
# Snapshot intervals
save 900 1 # at least 1 key change within 15 min
save 300 10 # at least 10 changes within 5 min
save 60 10000 # at least 10000 changes within 1 min
# Disable RDB (cache‑only)
save ""
# File name and directory
dbfilename dump.rdb
dir /var/lib/redis
# Stop writes on BGSAVE error
stop-writes-on-bgsave-error yes
# Compression and checksum
rdbcompression yes
rdbchecksum yesAdvantages :
Compact files, good for backup and disaster recovery.
Faster restoration of large datasets compared with AOF.
Disadvantages :
Potential data loss after the last snapshot.
Forking large datasets may cause brief pauses.
2.2 AOF (Append‑Only File) Persistence
AOF logs every write operation, providing higher durability.
# View AOF status
redis-cli INFO persistence
# Example fields:
# aof_enabled: 1
# aof_current_size: 1048576
# aof_last_write_status: okAOF settings (redis.conf) :
# Enable AOF
appendonly yes
# File name
appendfilename "appendonly.aof"
# Write policy (recommended)
appendfsync everysec # sync every second, may lose ≤1 s of data
# appendfsync always # safest, slowest
# appendfsync no # OS decides, fastest but unsafe
# Automatic rewrite
auto-aof-rewrite-percentage 100 # trigger when file grows 100 % larger than last rewrite
auto-aof-rewrite-min-size 64mb # rewrite only if file ≥64 MB
# Stop writes if rewrite fails
aof-load-truncated yes
# Hybrid persistence (Redis 7.0+)
aof-use-rdb-preamble yesAdvantages :
Higher data safety – at most one second of writes lost.
Append‑only writes avoid random‑write I/O.
Disadvantages :
File size larger than RDB.
Restoration slower than RDB.
2.3 Hybrid Persistence (Redis 4.0+)
# Enable hybrid persistence
aof-use-rdb-preamble yesDuring AOF rewrite, Redis stores a compact RDB snapshot followed by incremental AOF commands, combining fast recovery with durability.
2.4 Recovery Priority
If an AOF file exists, Redis restores from AOF.
If AOF is missing or corrupted, Redis falls back to the latest RDB.
2.5 Production‑Ready Persistence Settings
# Memory
maxmemory 8gb
maxmemory-policy allkeys-lru
# RDB
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
# AOF
appendonly yes
appendfsync everysec
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes3 Backup Strategy (RDB vs AOF)
3.1 Backup Script
#!/bin/bash
# redis_backup.sh
BACKUP_DIR="/data/redis_backup"
REDIS_HOST="127.0.0.1"
REDIS_PORT="6379"
REDIS_PASSWORD="your_redis_password"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
REDIS_DATA_DIR=$(redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD CONFIG GET dir | tail -1)
REDIS_DBFILE=$(redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD CONFIG GET dbfilename | tail -1)
REDIS_AOFFILE=$(redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD CONFIG GET appendfilename | tail -1)
# Trigger BGSAVE
echo "Triggering BGSAVE..."
redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD BGSAVE
# Wait for completion
while [ $(redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD LASTSAVE) -eq $(redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD LASTSAVE) ]; do
sleep 1
done
# Copy RDB
if [ -f "$REDIS_DATA_DIR/$REDIS_DBFILE" ]; then
cp $REDIS_DATA_DIR/$REDIS_DBFILE $BACKUP_DIR/dump_$DATE.rdb
echo "RDB backup: $REDIS_DBFILE"
fi
# Copy AOF
if [ -f "$REDIS_DATA_DIR/$REDIS_AOFFILE" ]; then
cp $REDIS_DATA_DIR/$REDIS_AOFFILE $BACKUP_DIR/appendonly_$DATE.aof
echo "AOF backup: $REDIS_AOFFILE"
fi
# Compress
cd $BACKUP_DIR
tar czf redis_backup_$DATE.tar.gz *.rdb *.aof 2>/dev/null
rm -f *.rdb *.aof
# Delete backups older than 7 days
find $BACKUP_DIR -name "redis_backup_*.tar.gz" -mtime +7 -delete
echo "Backup completed: redis_backup_$DATE.tar.gz"
ls -lh $BACKUP_DIR3.2 Restore Script
#!/bin/bash
# redis_restore.sh
BACKUP_FILE=$1
REDIS_HOST="127.0.0.1"
REDIS_PORT="6379"
REDIS_PASSWORD="your_redis_password"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 backup_file.tar.gz"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found"
exit 1
fi
# Stop Redis
echo "Stopping Redis..."
systemctl stop redis
# Backup current data
REDIS_DATA_DIR=$(redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD CONFIG GET dir | tail -1)
if [ -f "$REDIS_DATA_DIR/dump.rdb" ]; then
mv $REDIS_DATA_DIR/dump.rdb $REDIS_DATA_DIR/dump.rdb.bak
fi
if [ -f "$REDIS_DATA_DIR/appendonly.aof" ]; then
mv $REDIS_DATA_DIR/appendonly.aof $REDIS_DATA_DIR/appendonly.aof.bak
fi
# Extract backup
cd $REDIS_DATA_DIR
tar xzf $BACKUP_FILE
# Start Redis
echo "Starting Redis..."
systemctl start redis
# Verify data
KEY_COUNT=$(redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD DBSIZE)
echo "Restored keys: $KEY_COUNT"
# If nothing restored, roll back
if [ "$KEY_COUNT" -eq 0 ]; then
echo "Warning: No data restored, restoring from .bak files"
mv $REDIS_DATA_DIR/dump.rdb.bak $REDIS_DATA_DIR/dump.rdb
systemctl restart redis
fi4 Security Hardening
4.1 Password Authentication
# Temporary password
redis-cli CONFIG SET requirepass "your_strong_password"
# Permanent (redis.conf)
requirepass your_strong_password
# Connect with password
redis-cli -a your_strong_password
redis-cli -h 127.0.0.1 -p 6379 -a your_strong_password
# ACL (Redis 6.0+)
ACL SETUSER alice on >password ~cached:* +get +set +del +exists4.2 Bind Address
# Listen only on localhost
bind 127.0.0.1
# Listen on a specific internal IP
bind 192.168.1.100
# Multiple IPs
bind 127.0.0.1 192.168.1.100
# DO NOT bind to 0.0.0.0 in production4.3 Disable Dangerous Commands
# Rename to empty string (disabled)
rename-command FLUSHDB ""
rename-command FLUSHALL ""
rename-command DEBUG ""
rename-command KEYS ""
# Or rename to obscure names
rename-command FLUSHDB FLUSHDB_RENAMED
rename-command KEYS KEYSCMD4.4 Connection Limits
# Max clients
maxclients 10000
# TCP backlog
tcp-backlog 511
# Idle timeout (seconds)
timeout 300
# TCP keepalive (seconds)
tcp-keepalive 3004.5 Firewall Settings
# iptables example – allow only internal subnet
iptables -A INPUT -p tcp -s 192.168.1.0/24 --dport 6379 -j ACCEPT
iptables -A INPUT -p tcp --dport 6379 -j DROP
# In cloud environments, use security groups to restrict access to application servers only.4.6 Security Checklist Script
#!/bin/bash
# redis_security_check.sh
echo "=== Redis Security Check ==="
# 1. Password set?
REQUIREPASS=$(redis-cli CONFIG GET requirepass | tail -1)
if [ -z "$REQUIREPASS" ]; then
echo "[WARN] Redis password not set!"
else
echo "[OK] Password configured"
fi
# 2. Bind address
BIND=$(redis-cli CONFIG GET bind | tail -1)
if [[ "$BIND" == *"0.0.0.0"* ]]; then
echo "[WARN] Binding to 0.0.0.0 – insecure!"
else
echo "[OK] Bind address: $BIND"
fi
# 3. Dangerous commands disabled?
DEBUG=$(redis-cli CONFIG GET rename-command | grep -c DEBUG)
if [ $DEBUG -gt 1 ]; then
echo "[WARN] DEBUG command not disabled!"
else
echo "[OK] DEBUG command disabled or renamed"
fi
# 4. Max clients
MAXCLIENTS=$(redis-cli CONFIG GET maxclients | tail -1)
echo "Max clients: $MAXCLIENTS"
# 5. Protected mode
PROTECTED=$(redis-cli CONFIG GET protected-mode | tail -1)
if [ "$PROTECTED" = "yes" ]; then
echo "[OK] Protected mode enabled"
else
echo "[WARN] Protected mode disabled!"
fi
# 6. Running as root?
REDIS_USER=$(ps aux | grep redis-server | grep -v grep | awk '{print $1}')
if [ "$REDIS_USER" = "root" ]; then
echo "[WARN] Redis runs as root!"
else
echo "[OK] Redis runs as $REDIS_USER"
fi
echo "=== Check Complete ==="5 Master‑Slave Replication
5.1 Basic Replication Setup
# In replica's redis.conf
replicaof 192.168.1.100 6379
# Or on the fly
redis-cli REPLICAOF 192.168.1.100 6379
# Promote to master
redis-cli REPLICAOF NO ONE5.2 Replication Parameters
# Replica settings
replica-serve-stale-data yes # serve reads when master is down
replica-read-only yes # read‑only replica
repl-diskless-sync no # use disk‑based sync
repl-diskless-sync-delay 5 # delay for diskless sync
repl-disable-tcp-nodelay no # TCP_NODELAY handling
replica-priority 100 # used by Sentinel election5.3 Verify Replication State
# Master view
redis-cli INFO replication
# Sample output:
# role:master
# connected_slaves:2
# slave0:ip=192.168.1.101,port=6379,state=online,offset=12345,lag=0
# Replica view
# role:slave
# master_host:192.168.1.100
# master_link_status:up
# Check lag (simple method)
redis-cli -h slave_ip REPLICAOF NO ONE # then compare DBSIZE on both sides6 Sentinel Cluster
6.1 Sentinel Configuration (sentinel.conf)
# Sentinel port
port 26379
# Monitor master
sentinel monitor mymaster 192.168.1.100 6379 2
# Optional auth
sentinel auth-pass mymaster your_password
# Down‑after timeout (ms)
sentinel down-after-milliseconds mymaster 30000
# Failover timeout (ms)
sentinel failover-timeout mymaster 180000
# Parallel syncs during failover
sentinel parallel-syncs mymaster 1
# Known replicas and sentinels for auto‑discovery
sentinel known-replica mymaster 192.168.1.101 6379
sentinel known-sentinel mymaster 192.168.1.200 263796.2 Starting Sentinel
# Direct start
redis-sentinel /etc/redis/sentinel.conf
# Or via redis‑server
redis-server /etc/redis/sentinel.conf --sentinel
# Check status
redis-cli -p 26379 INFO sentinel
redis-cli -p 26379 SENTINEL masters
redis-cli -p 26379 SENTINEL MASTER mymaster
redis-cli -p 26379 SENTINEL REPLICAS mymaster6.3 Deployment Recommendations
Deploy at least three Sentinel instances.
Place each Sentinel on a different physical machine.
Number of Sentinels ≥ (2 × number_of_masters + 1).
Quorum should be (sentinel_count / 2) + 1.
7 Redis Cluster Mode
7.1 Cluster Configuration (redis.conf)
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 15000
cluster-replica-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes7.2 Creating a Cluster
# Assume six instances (3 masters, 3 replicas)
redis-cli --cluster create \
192.168.1.101:6379 \
192.168.1.102:6379 \
192.168.1.103:6379 \
192.168.1.104:6379 \
192.168.1.105:6379 \
192.168.1.106:6379 \
--cluster-replicas 1
# "--cluster-replicas 1" creates one replica per master.7.3 Cluster Management Commands
# Cluster info
redis-cli -c -h 192.168.1.101 -p 6379 CLUSTER INFO
# Node list
redis-cli -c -h 192.168.1.101 -p 6379 CLUSTER NODES
# Slot distribution
redis-cli -c -h 192.168.1.101 -p 6379 CLUSTER SLOTS
# Add a new node
redis-cli --cluster add-node 192.168.1.107:6379 192.168.1.101:6379
# Add a replica
redis-cli --cluster add-node 192.168.1.108:6379 192.168.1.101:6379 --cluster-slave
# Delete a node
redis-cli --cluster del-node 192.168.1.101:6379 node_id
# Reshard slots
redis-cli --cluster reshard 192.168.1.101:6379
# Rebalance slots
redis-cli --cluster rebalance 192.168.1.101:6379
# Manual failover (run on a replica)
redis-cli -h 192.168.1.104 -p 6379 CLUSTER FAILOVER7.4 Scaling the Cluster
# Expand – add a new master
redis-server /etc/redis/redis.conf --daemonize yes
redis-cli --cluster add-node 192.168.1.107:6379 192.168.1.101:6379
redis-cli --cluster reshard 192.168.1.101:6379 # follow prompts to assign slots
# Shrink – move slots away then delete
redis-cli --cluster reshard 192.168.1.101:6379 # move slots to other masters
redis-cli --cluster del-node 192.168.1.101:6379 node_id_of_192.168.1.1078 Monitoring & Alerting
8.1 INFO Command Details
# All sections
redis-cli INFO
# Specific sections
redis-cli INFO server # server info
redis-cli INFO clients # client connections
redis-cli INFO memory # memory usage
redis-cli INFO persistence # RDB/AOF status
redis-cli INFO stats # command stats, QPS
redis-cli INFO replication # replication state
redis-cli INFO cpu # CPU usage
redis-cli INFO commandstats# per‑command stats
redis-cli INFO latencystats# latency distribution
redis-cli INFO sentinel # sentinel status8.2 Key Monitoring Metrics
# Memory usage
redis-cli INFO memory | grep -E "used_memory_human|maxmemory_human|mem_fragmentation_ratio"
# Connection count
redis-cli INFO clients
# Example fields: connected_clients: 100, blocked_clients: 0
# QPS
redis-cli INFO stats | grep -E "instantaneous_ops_per_sec|total_commands_processed"
# Replication lag
redis-cli INFO replication | grep -E "master_repl_offset|replica_offset"
# Persistence status
redis-cli INFO persistence | grep -E "rdb_last_bgsave_status|aof_last_write_status"8.3 Slow‑Query Log
# Enable slowlog (threshold 10 ms)
redis-cli CONFIG SET slowlog-log-slower-than 10000
redis-cli CONFIG SET slowlog-max-len 128
# View recent entries
redis-cli SLOWLOG GET 10
# Clear log
redis-cli SLOWLOG RESET
# Entry fields example:
# 1) ID (integer)
# 2) Unix timestamp
# 3) Execution time (µs)
# 4) Command and arguments (array)
# 5) Client IP/port8.4 Monitoring Script (bash)
#!/bin/bash
ALERT_EMAIL="[email protected]"
REDIS_HOST="127.0.0.1"
REDIS_PORT="6379"
REDIS_PASSWORD=""
WARN_MEMORY_PCT=80
CRIT_MEMORY_PCT=90
# Memory usage percentage
MEMORY_INFO=$(redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD INFO memory 2>/dev/null)
USED=$(echo "$MEMORY_INFO" | grep used_memory: | cut -d: -f2)
MAX=$(redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD CONFIG GET maxmemory | tail -1)
MEMORY_PCT=$(echo "scale=2; $USED*100/$MAX" | bc)
echo "Memory usage: ${MEMORY_PCT}%"
if (( $(echo "$MEMORY_PCT > $CRIT_MEMORY_PCT" | bc -l) )); then
echo "CRITICAL: Memory > $CRIT_MEMORY_PCT%" | mail -s "[CRITICAL] Redis memory alert" $ALERT_EMAIL
elif (( $(echo "$MEMORY_PCT > $WARN_MEMORY_PCT" | bc -l) )); then
echo "WARNING: Memory > $WARN_MEMORY_PCT%" | mail -s "[WARNING] Redis memory alert" $ALERT_EMAIL
fi
# Connection count
CLIENTS=$(redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD INFO clients | grep connected_clients | cut -d: -f2)
echo "Connections: $CLIENTS"
# Replication lag (basic view)
REPL_LAG=$(redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD INFO replication | grep -E "master_repl_offset|replica0:offset")
echo "Replication status: $REPL_LAG"
# Persistence health
PERSISTENCE=$(redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD INFO persistence | grep -E "rdb_last_bgsave_status|aof_last_write_status")
echo "Persistence status: $PERSISTENCE"9 Common Issues & Solutions
9.1 OOM (Out‑of‑Memory)
Symptom : OOM command not allowed when used memory > 'maxmemory' Investigation :
Check used memory: redis-cli INFO memory | grep used_memory Check maxmemory setting.
Identify large keys: redis-cli --bigkeys or
redis-cli --scan | head -1000 | xargs -I {} redis-cli DEBUG OBJECT ENCODING {}Resolution :
Increase maxmemory.
Adjust eviction policy.
Delete unnecessary data.
Shard data using Redis Cluster.
9.2 Persistence Failure
Symptom : Background saving error or BGSAVE failed Investigation :
Inspect INFO persistence for last save status.
Check disk space with df -h.
Verify Redis data directory permissions.
Resolution :
Free up disk space.
Ensure the Redis user can write to the directory.
Change dir to a partition with sufficient space.
9.3 Replication Disconnection
Symptom : Disconnected from master, master_link_status: down Investigation :
Run redis-cli INFO replication.
Test connectivity: telnet 192.168.1.100 6379 or ping.
Resolution :
Ensure the master is reachable (network, firewall).
Check firewall rules.
If the master is down, wait for Sentinel failover or promote a replica manually.
9.4 High Latency
Symptom : Redis responses become slow.
Investigation :
Inspect slowlog: redis-cli SLOWLOG GET 10.
Find large keys: redis-cli --bigkeys.
Check CPU usage: top -p $(pidof redis-server).
Check memory fragmentation ratio.
Resolution :
Optimize slow queries.
Split or redesign large keys.
Run active defragmentation.
Scale out by adding more Redis instances.
10 Summary & Checklist
10.1 Production‑Readiness Checklist
maxmemory : set to 70‑80 % of physical RAM.
Eviction policy : use allkeys-lru for typical cache workloads.
Persistence : enable both RDB and AOF (hybrid) for safety.
AOF policy : appendfsync everysec balances performance and durability.
Password : enforce a strong password.
Bind address : listen only on internal IPs.
Dangerous commands : rename or disable (e.g., FLUSHALL, DEBUG, KEYS).
Backup : daily backups, retain for 7 days.
Monitoring : track memory, connections, QPS, slowlog.
Logging : enable slow‑query log.
10.2 Recommended redis.conf Template (Production)
# Network
bind 192.168.1.100
port 6379
timeout 300
tcp-keepalive 300
# Security
requirepass your_strong_password
rename-command FLUSHDB ""
rename-command FLUSHALL ""
rename-command DEBUG ""
rename-command KEYS ""
# Memory
maxmemory 8gb
maxmemory-policy allkeys-lru
maxmemory-samples 5
# Persistence
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
appendonly yes
appendfsync everysec
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
# Defragmentation
activedefrag yes10.3 Operational Tips
Avoid KEYS in production : it blocks the server. Use SCAN instead.
# Wrong
redis-cli KEYS "user:*"
# Correct
redis-cli --scan --pattern "user:*" | head -1000Use connection pools to reduce connection churn.
# Python example
import redis
pool = redis.ConnectionPool(host='127.0.0.1', port=6379, password='pass', max_connections=50)
client = redis.Redis(connection_pool=pool)Set appropriate TTLs to prevent unbounded growth.
# 24‑hour expiration
SET session:12345 "data" EX 86400
# or
EXPIRE session:12345 86400Regularly review memory usage, connection count, and slow‑query logs.
Redis appears simple, but production deployments contain many hidden pitfalls. Following the guidelines above helps build a stable, reliable Redis service.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
