1. Using Pipelining Effectively
| Aspect | Detail |
| Batch size | 100–1000 typically optimal |
| Avoid | Mixing reads + writes where you need responses mid-stream |
2. Avoiding Large Operations
Warning: Avoid KEYS, large HGETALL/SMEMBERS, big DEL. Prefer SCAN, paginated retrieval, UNLINK.
3. Using SCAN Instead of KEYS
| Command | Notes |
SCAN cursor [MATCH p] [COUNT n] [TYPE t] | Non-blocking iteration |
HSCAN, SSCAN, ZSCAN | Per-collection variants |
4. Using UNLINK for Large Keys
| Command | Description |
UNLINK key [key ...] | Asynchronous DEL — frees memory in background |
5. Enabling Lazy Free
| Directive | Effect |
lazyfree-lazy-eviction yes | Background free on eviction |
lazyfree-lazy-expire yes | Background free on TTL expiry |
lazyfree-lazy-server-del yes | Replace large keys async |
lazyfree-lazy-user-del yes | Make DEL behave like UNLINK |
lazyfree-lazy-user-flush yes | FLUSHALL/FLUSHDB async by default |
6. Configuring IO Threads
io-threads 4
io-threads-do-reads yes
| Directive | Effect |
io-threads | Parallelize socket read/write parsing |
| Best for | High-throughput workloads with large values |
7. Tuning TCP Parameters
| Directive | Description |
tcp-backlog 511 | Match OS somaxconn |
tcp-keepalive 300 | Probe interval |
8. Disabling Transparent Huge Pages
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
Note: THP causes large fork-time latency spikes.
9. Configuring Kernel Parameters
| Sysctl | Setting |
vm.overcommit_memory | 1 — required for BGSAVE under memory pressure |
net.core.somaxconn | ≥ 511 |
net.ipv4.tcp_max_syn_backlog | Match somaxconn |
fs.file-max / ulimit -n | ≥ maxclients + headroom |
10. Using CONFIG SET for Runtime Changes
| Command | Description |
CONFIG GET parameter | Read current value(s) |
CONFIG SET key value | Change without restart |
CONFIG REWRITE | Persist runtime changes to disk |
CONFIG RESETSTAT | Reset INFO counters |
11. Benchmarking with redis-benchmark
redis-benchmark -h host -p 6379 -c 50 -n 1000000 -t get,set -P 16
redis-benchmark -t set -r 100000 -d 1024 --csv
redis-benchmark -t set -r 100000 --cluster
| Flag | Description |
-c | Parallel clients |
-n | Total requests |
-P | Pipeline depth |
-r | Random keyspace size |
-d | Value size (bytes) |
--cluster | Cluster-aware |
12. Optimizing Network Latency
| Optimization | Detail |
| Co-locate | Place app and Redis in same AZ |
| Pipelining | Amortize RTT cost |
| Unix sockets | unixsocket /var/run/redis.sock for same-host clients |
| Client-side cache | Use CLIENT TRACKING for hot reads |