Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

redis-cli

The client for Redis and Valkey: the in-memory key-value store used for caches, sessions, queues and rate limits.

Level
DevSecOps service
Group
Databases and messaging
Needs root
No
Package
redis
Also called
redis, valkey-cli

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.
SET key value [EX sec] / GET key
Write / read.
DEL / EXPIRE / TTL key
Delete / set or read expiry.
SCAN 0 MATCH pattern COUNT 100
Find keys safely (not KEYS *).
INFO [section]
Server stats (memory, clients, replication).
ACL SETUSER / ACL LIST / ACL WHOAMI
Users and rights.
CONFIG GET name
Read a setting.
SLOWLOG GET 10
Slow commands.
MONITOR
Show every command live (debug only).
DBSIZE
Number of keys.

Options 9

Most used

Flags

-h HOST / -p PORT
Server.
--user USER --pass PASS
ACL login (prefer REDISCLI_AUTH env var).
--tls --cacert FILE
TLS connection.
-n DB
Database number.
--scan --pattern P
List keys with SCAN.
--bigkeys / --memkeys
Find big keys.
--latency / --latency-history
Measure latency.
--stat
Live stats every second.
-r N -i SEC
Repeat a command.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Install and test

    dnf install -y valkey
    systemctl enable --now valkey
    valkey-cli ping
    PONG
  2. 2Write and read with expiry

    redis-cli SET session:42 '{"user":"hosam"}' EX 3600
    redis-cli TTL session:42
    redis-cli GET session:42
  3. 3Find keys without blocking the server

    redis-cli --scan --pattern 'session:*' | head
    redis-cli DBSIZE
  4. 4Create 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:42
  5. 5Check memory and big keys

    redis-cli INFO memory | grep -E "used_memory_human|maxmemory_human"
    redis-cli --bigkeys
  6. 6Measure latency

    redis-cli --latency-history -i 5
  7. 7Find slow commands

    redis-cli SLOWLOG GET 5
  8. 8Secure 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-lru
  9. 9Connect with TLS

    redis-cli -h cache.lab.local -p 6380 --tls --cacert /etc/pki/tls/certs/lab-ca.crt PING
  10. 10Run in Kubernetes and test

    kubectl run -it --rm rcli --image=docker.io/valkey/valkey:8 -- valkey-cli -h valkey.shop.svc PING

Watch out

  • KEYS * and FLUSHALL on 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 maxmemory and 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

0Success.
1Error (connection, auth).