What it does
Redis keeps data in memory (port 6379) and is very fast. Apps use it for caching, sessions, queues (lists, streams) and rate limiting. Valkey is the open-source fork (Linux Foundation) with the same commands; RHEL 10 ships Valkey. redis-cli runs commands, monitors the server and measures latency.
Security: Redis must never be open to the internet. Use requirepass or ACL users, bind to private addresses, and TLS when traffic leaves the host.
How to write it
redis-cli [-h HOST] [-p PORT] [--user U --pass P | -a PASS] [--tls] [COMMAND ...]Main parts
Common commands
PING- Test the connection.
SETkeyvalue[EX sec]/GETkey- Write / read.
DEL/EXPIRE/TTLkey- Delete / set or read expiry.
SCAN0MATCHpatternCOUNT100- Find keys safely (not KEYS *).
INFO[section]- Server stats (memory, clients, replication).
ACLSETUSER/ACLLIST/ACLWHOAMI- Users and rights.
CONFIGGETname- Read a setting.
SLOWLOGGET10- Slow commands.
MONITOR- Show every command live (debug only).
DBSIZE- Number of keys.
Options 9
Most used
Flags
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Install and test
2Write and read with expiry
redis-cli SET session:42 '{"user":"hosam"}' EX 3600 redis-cli TTL session:42 redis-cli GET session:423Find keys without blocking the server
redis-cli --scan --pattern 'session:*' | head redis-cli DBSIZE4Create an app user with ACLs
redis-cli ACL SETUSER shop on '>Ch4nge-me-2026' '~shop:*' '+@read' '+@write' '-@dangerous' redis-cli ACL LIST REDISCLI_AUTH='Ch4nge-me-2026' redis-cli --user shop GET shop:cart:425Check memory and big keys
redis-cli INFO memory | grep -E "used_memory_human|maxmemory_human" redis-cli --bigkeys6Measure latency
redis-cli --latency-history -i 57Find slow commands
redis-cli SLOWLOG GET 58Secure the config
cat /etc/valkey/valkey.conf bind 127.0.0.1 10.20.2.20 protected-mode yes rename-command FLUSHALL "" maxmemory 512mb maxmemory-policy allkeys-lru9Connect with TLS
redis-cli -h cache.lab.local -p 6380 --tls --cacert /etc/pki/tls/certs/lab-ca.crt PING10Run in Kubernetes and test
kubectl run -it --rm rcli --image=docker.io/valkey/valkey:8 -- valkey-cli -h valkey.shop.svc PING
Nothing matches this filter.
Watch out
KEYS *andFLUSHALLon production can block or wipe the server; use SCAN and rename dangerous commands.- An open Redis lets attackers write files and get a shell on the host — bind to private IPs and set a password.
- Set
maxmemoryand a policy, or Redis uses all RAM.
Files
/etc/redis/redis.conf or /etc/valkey/valkey.conf- Server config.
/var/lib/redis/- dump.rdb / appendonly files.
Tips to remember
- Use Redis as a cache that can be lost; for data that must not be lost, turn on AOF and backups.
Exit codes
0 | Success. |
1 | Error (connection, auth). |