Skip to main content
Databases

Redis CLI & Data Structures

Essential

Redis command syntax, strings, hashes, sorted sets, pub/sub, expiration TTLs, clustering, and memory monitoring.

Instant Copy & SearchProduction Flagged SyntaxCurrent Flag Reference

Redis CLI & Data Structures Interactive Command Directory

Browse, search, and copy battle-tested commands & syntax recipes (17 Total Commands).

17+ Verified Recipes
Connection-h, -p, -a, --latency
redis-cli -h 127.0.0.1 -p 6379 -a "my_secret_auth" --latency

Connect to Redis server and measure continuous network round-trip ping latency.

Strings & TTLEX, NX
SET session:user:42 "{token: 'xyz'}" EX 3600 NX

Set string with 1-hour expiration only if key does not already exist.

String QueryGET, TTL
GET session:user:42 && TTL session:user:42

Retrieve value of key and inspect remaining time-to-live in seconds.

HashesHSET
HSET user:100 name "Alex" role "Admin" email "alex@domain.com"

Set multiple field-value pairs on a Redis hash in a single operation.

HashesHGETALL
HGETALL user:100

Retrieve all fields and associated values stored in a hash.

Lists & QueuesLPUSH, RPOP
LPUSH queue:jobs "job_101" && RPOP queue:jobs

Push items onto head of list and pop from tail to implement FIFO queue.

SetsSADD, SMEMBERS
SADD tags:article:5 "javascript" "database" && SMEMBERS tags:article:5

Add elements to unique unordered set and query all set members.

Sorted SetsZADD, ZREVRANGE
ZADD leaderboard 2500 "player1" 1800 "player2" && ZREVRANGE leaderboard 0 9 WITHSCORES

Maintain rank scores and query top 10 elements with associated scores.

Memory DiagnosticsINFO memory
INFO memory

Display detailed memory consumption, fragmentation ratio, and peak allocations.

Live MonitoringMONITOR
MONITOR

Stream every single command processed by the Redis server in real-time.

Safe IterationSCAN, MATCH, COUNT
SCAN 0 MATCH "user:session:*" COUNT 100

Cursor-based non-blocking pattern scanning replacing latency-inducing KEYS commands in production.

Distributed LockingEVAL, Lua
EVAL "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end" 1 lock:order_123 unique_client_token

Atomically release distributed lock only if token matches, preventing race condition accidental lock deletions.

Streams & MessagingXADD, XREAD
XADD mystream * sensor-id 1234 temperature 19.8 && XREAD COUNT 1 STREAMS mystream 0

Append structured event to Redis stream and read stream items from beginning offset.

Memory ProfilingMEMORY USAGE, DOCTOR
MEMORY USAGE user:100 && MEMORY DOCTOR

Inspect exact byte consumption for specific keys and evaluate instance memory health and fragmentation.

Eviction ConfigurationCONFIG GET/SET
CONFIG GET maxmemory-policy && CONFIG SET maxmemory-policy allkeys-lru

Inspect and update runtime key eviction policies under memory pressure without server reboot.

Latency DiagnosticsSLOWLOG GET
SLOWLOG GET 10 && SLOWLOG RESET

Query execution latency log for queries exceeding slowlog-log-slower-than threshold.

Connection ManagementCLIENT LIST/KILL
CLIENT LIST && CLIENT KILL TYPE normal

List connected client file descriptors, memory usage, and idle time, terminating rogue unmanaged connections.

Zero Setup100% In-Browser Execution

Companion Developer Tools & Playgrounds

Accelerate command execution and syntax debugging with HelloAIHub suite of interactive tools.

Explore all developer tools

Redis CLI & Data Structures: Command Groups & Quick Index

17 indexed entries across 16 sections
Connection1 items
Strings & TTL1 items
String Query1 items
Hashes2 items
Lists & Queues1 items
Sets1 items
Sorted Sets1 items
Memory Diagnostics1 items
Live Monitoring1 items
Safe Iteration1 items
Distributed Locking1 items
Streams & Messaging1 items
Memory Profiling1 items
Eviction Configuration1 items
Latency Diagnostics1 items
Connection Management1 items

Highlighted Flags & Syntax Examples in Redis CLI & Data Structures

redis-cli -h 127.0.0.1 -p 6379 -a "my_secret_auth" --latency

Connect to Redis server and measure continuous network round-trip ping latency.

Flags: -h, -p, -a, --latency
SET session:user:42 "{token: 'xyz'}" EX 3600 NX

Set string with 1-hour expiration only if key does not already exist.

Flags: EX, NX
GET session:user:42 && TTL session:user:42

Retrieve value of key and inspect remaining time-to-live in seconds.

Flags: GET, TTL
HSET user:100 name "Alex" role "Admin" email "alex@domain.com"

Set multiple field-value pairs on a Redis hash in a single operation.

Flags: HSET

Frequently Asked Questions

Expert recommendations, common traps, and production best practices for Redis CLI & Data Structures.

Why is KEYS * considered dangerous in production Redis?

Redis is single-threaded. KEYS * scans the entire keyspace synchronously, blocking all incoming client requests for seconds or minutes on large datasets. Use SCAN instead, which iterates incrementally with a cursor.

What is the difference between RDB snapshots and AOF persistence?

RDB creates point-in-time binary snapshots of the dataset at specified intervals. AOF (Append Only File) logs every write operation received, providing superior durability with minimal data loss risk at slight write-latency cost.

How does Redis achieve single-threaded high performance and when does it use background threads?

Redis processes commands on a single thread using non-blocking I/O multiplexing (epoll/kqueue), eliminating mutex locking, context switching, and thread contention overhead while serving data from RAM. Since Redis 6.0, auxiliary threads handle network socket read/write operations, while background threads perform asynchronous disk fsyncs and memory reclamation.

What eviction policy should you choose when Redis reaches its maxmemory limit?

Use 'allkeys-lru' or 'allkeys-lfu' when Redis acts as an ephemeral cache where any cold key can safely be discarded. Use 'volatile-lru' or 'volatile-ttl' when Redis stores both persistent data and cached data, ensuring only keys with explicit TTL expiration headers are evicted.

How do Redis Streams compare to Pub/Sub and lists for message queuing?

Pub/Sub is 'fire-and-forget' with no persistence or message acknowledgement; offline subscribers lose messages. Lists provide simple FIFO queuing but lack multi-consumer fanout without duplicating data. Redis Streams provide durable append-only logging, consumer groups, automatic offset tracking, and explicit ACK handling.

How can you implement a distributed lock safely in Redis without race conditions?

Acquire the lock using 'SET key unique_uuid NX PX timeout_ms'. Releasing the lock requires an atomic Lua script verifying that the current key value equals unique_uuid before executing DEL. This prevents Client A from deleting Client B's lock if Client A's transaction exceeded the lock timeout duration.

Cross-Hub Skill Acceleration

Combine command lookups with active coding interviews and complete career paths.

Need More Cheat Sheets?

Explore developer cheat sheets and syntax guides on HelloAIHub.

Browse All Cheat Sheets