Mastering Redis Configuration: Units, Security, Persistence, and Cluster Settings
This guide provides a comprehensive walkthrough of Redis configuration options, covering memory unit notation, include templates, module loading, security settings, networking, persistence mechanisms, replication, clustering, Docker deployment, monitoring, and advanced memory and performance tuning.
Memory units : Redis accepts size specifications like 1k (1000 bytes), 1kb (1024 bytes), 1m (1,000,000 bytes), 1mb (1,048,576 bytes), 1g (1,000,000,000 bytes), and 1gb (1,073,741,824 bytes); units are case‑insensitive.
Include templates
Use include /path/to/local.conf to pull in additional configuration files for per‑server customisation while keeping a common base template.
Module loading
Modules can be loaded at startup with loadmodule /path/to/mymodule.so or dynamically via the MODULE LOAD command; parameters can be passed (e.g., loadmodule mymodule.so foo bar 123456). Use MODULE LIST to view loaded modules and MODULE UNLOAD to remove them.
Security – bind and protected‑mode
Default protected-mode yes blocks public access. It is triggered when no bind IP and no password are set. bind 127.0.0.1 restricts access to localhost; bind 0.0.0.0 disables binding.
Network settings
Port defaults to 6379. tcp-backlog 511 controls the accept queue size; increase it for high‑concurrency workloads.
Unix socket: unixsocket /tmp/redis.sock and unixsocketperm 700.
Idle client timeout: timeout 0 (never close) – recommended 300 seconds.
Keep‑alive: tcp-keepalive 300.
Daemonisation
daemonize no(default) runs Redis in the foreground; supervised no leaves process supervision to the OS (upstart/systemd). pidfile /var/run/redis_6379.pid sets the PID file location.
Logging
Log levels: debug, verbose, notice, warning. Log output can be sent to syslog with syslog-enabled yes and configured via syslog-ident and syslog-facility.
Persistence – snapshots and AOF
Snapshot rules (RDB): save 900 1, save 300 10, save 60 10000. Additional flags control write‑on‑error, compression, checksum, filename, and directory.
AOF settings include appendonly no, appendfsync everysec (default), appendfsync always (safest but slowest), and no-appendfsync-on-rewrite to avoid blocking during background rewrite. Auto‑rewrite thresholds are set with auto-aof-rewrite-percentage and auto-aof-rewrite-min-size. Truncated AOF handling is controlled by aof-load-truncated.
Replication
Configure a master with replicaof <masterip> <masterport> and optional masterauth. replica-serve-stale-data determines behaviour when the master is unreachable. replica-read-only yes makes replicas read‑only. Disk‑less sync, backlog size, priority, and minimum‑replicas‑to‑write settings fine‑tune failover behavior.
Cluster mode
Enable with cluster-enabled yes. Important options: cluster-config-file, cluster-node-timeout, cluster-replica-validity-factor, cluster-require-full-coverage, and cluster-replica-no-failover. In Docker, set cluster-announce-ip, cluster-announce-port, and cluster-announce-bus-port so containers expose reachable addresses.
Monitoring and alerts
Latency monitor: latency-monitor-threshold 0 disables it; set a positive value to record slow operations.
Slowlog: slowlog-log-slower-than 10000 (microseconds) and slowlog-max-len 128.
Keyspace notifications: notify-keyspace-events Ex for expiration events.
Data‑structure tuning
Adjust ziplist thresholds for hashes, lists, sets, and sorted sets (e.g., hash-max-ziplist-entries 512, list-max-ziplist-size -2, zset-max-ziplist-entries 128). Control quicklist compression depth with list-compress-depth. Enable or disable active rehashing with activerehashing yes|no. Client output buffer limits can be set per connection class.
Memory fragmentation defragmentation
Activate with activedefrag yes and tune thresholds ( active-defrag-threshold-lower, active-defrag-threshold-upper), cycle limits, and scan field limits.
Other useful settings
HZ and dynamic‑hz control server task frequency.
Incremental fsync for AOF and RDB: aof-rewrite-incremental-fsync yes, rdb-save-incremental-fsync yes.
LFU algorithm parameters ( lfu-log-factor, lfu-decay-time) for eviction policies.
This collection of configuration snippets equips operators with the knowledge to fine‑tune Redis for security, performance, durability, and scalability across diverse deployment scenarios.
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.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
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.
