Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

redis-cli

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

Niveau
DevSecOps-service
Groep
Databases en messaging
Root nodig
Nee
Pakket
redis
Ook
redis, valkey-cli

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

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.

Zo schrijf je het

redis-cli [-h HOST] [-p PORT] [--user U --pass P | -a PASS] [--tls] [COMMAND ...]

Belangrijkste delen

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.

Opties 9

Meest gebruikt

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.

Voorbeelden 10

$ als gewone gebruiker# als root (of met 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

Let op

  • 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.

Bestanden

/etc/redis/redis.conf or /etc/valkey/valkey.conf
Server config.
/var/lib/redis/
dump.rdb / appendonly files.

Tips om te onthouden

  • Use Redis as a cache that can be lost; for data that must not be lost, turn on AOF and backups.

Exitcodes

0Success.
1Error (connection, auth).

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man redis-cli