الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

redis-cli

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

المستوى
خدمة DevSecOps
المجموعة
قواعد البيانات والرسائل
يحتاج root
لا
الحزمة
redis
يُسمّى أيضًا
redis, valkey-cli

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

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

الأجزاء الرئيسية

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.

الخيارات 9

الأكثر استخدامًا

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.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع 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

انتبه

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

الملفات

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

نصائح للحفظ

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

رموز الخروج

0Success.
1Error (connection, auth).

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man redis-cli