$ run as a normal user# run as root (or with sudo)
The quick answer
export REDISCLI_AUTH='<password>'
redis-cli INFO memory | grep -E 'used_memory_human|maxmemory_human|maxmemory_policy|mem_fragmentation_ratio'
redis-cli INFO keyspace
db0:keys=184233,expires=12041,avg_ttl=86012345
redis-cli --bigkeys
redis-cli --memkeysREDISCLI_AUTH keeps the password out of the process list (better than -a). On RHEL 10 the client is valkey-cli — same commands.
Step by step
- The memory numbers:
| Field | Means |
|---|---|
used_memory_human | Memory used by the data. |
maxmemory_human | The limit (0B = no limit — dangerous on a shared server). |
maxmemory_policy | What happens at the limit (see step 4). |
mem_fragmentation_ratio | Above about 1.5 = much wasted RAM (fragmentation). |
evicted_keys (in INFO stats) | Keys removed because memory was full. |
- Find big keys —
--bigkeysand--memkeysscan withSCAN(safe, small steps). Then look at one key:
redis-cli MEMORY USAGE session:4f1c2a
(integer) 1048712
redis-cli TYPE session:4f1c2a
redis-cli TTL session:4f1c2a
(integer) -1TTL -1 = no expiry — this key lives forever.
- Count keys by prefix, safely — never
KEYS *on production (it blocks Redis until it is done):
redis-cli --scan --pattern 'session:*' | wc -l
redis-cli --scan --pattern 'cache:*' --count 1000 | head- The eviction policy decides what happens at
maxmemory:
| Policy | Use |
|---|---|
noeviction | Writes fail with an error — for data you must not lose (queues). |
allkeys-lru | Remove the least used keys — a pure cache. |
volatile-lru / volatile-ttl | Remove only keys with an expiry. |
CONFIG REWRITE saves the change in the config file (or set it in redis.conf directly).
- Slow commands and latency:
- Keep it healthy: set a
maxmemorybelow the server RAM, give every cache key a TTL, monitorused_memory,evicted_keysandconnected_clients(redis_exporter + Prometheus).
Check that it worked
used_memory is clearly below maxmemory, evicted_keys does not grow (unless it is a cache by design), big keys are known and have a TTL, and the app shows no OOM errors.
Common problems
| Problem | Cause | Fix |
|---|---|---|
OOM command not allowed when used memory > 'maxmemory' | Limit reached with noeviction. | Free keys, add TTLs, raise maxmemory, or use an eviction policy for a cache. |
NOAUTH Authentication required | Password not given. | REDISCLI_AUTH or redis-cli --user NAME --askpass. |
| Redis froze for seconds | KEYS *, a huge DEL, or SAVE on a big dataset. | Use SCAN, UNLINK (deletes in the background), BGSAVE. |
| Memory keeps growing | Keys without TTL (sessions, caches). | Set TTLs in the app; find them with --scan + TTL. |
High mem_fragmentation_ratio | Many deletes/updates of different sizes. | CONFIG SET activedefrag yes (Redis/Valkey with jemalloc), or a planned restart. |
| The server swaps | maxmemory too high for the RAM, or no limit. | Set maxmemory to about 70–80 % of free RAM. |
Go further
- Command pages: redis-cli.
- Next how-tos: Check memory and CPU usage, See who is connected to a database, Monitor a Linux server with Prometheus, Connect apps to Redis securely.
- Full guide: Install and set up Redis / Valkey. At work: Redis in daily use. Cache servers: Memcached.
1Why must you never run KEYS * on a production Redis?
It blocks Redis until it has read every key; use SCAN (redis-cli --scan) instead.
2What does TTL key returning -1 mean?
The key exists and has no expiry — it stays until it is deleted.