Database & Cache
Updated for 2026

Redis Commands & Key-Value Store Cheatsheet 2026

Reference guide for Redis strings, hashes, lists, sets, sorted sets, key expiration rules, pub/sub messaging, and server admin commands.

Keys & Expiration

EXISTS key
Check if a specified key exists in the database. Returns 1 or 0.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

EXISTS key

Output Example

Console / Terminal
OK
EXPIRE key 60
Set an expiration TTL (Time-to-Live) timer in seconds on a key.

When to Use

When storing or fetching standard string values, setting key timers, or configuring auto-expiration TTLs.

Common Mistakes

Forgetting that updating a key with SET will overwrite and clear any previously configured EXPIRE TTL timer.

Shortcut / Pro-Tip

Use TTL command to inspect how many seconds are left before a cached key expires.

Example

EXPIRE key 60

Output Example

Console / Terminal
OK
TTL key
Query the remaining expiration duration in seconds of a key.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

TTL key

Output Example

Console / Terminal
OK
KEYS *
Search and list all keys matching a pattern. (Warning: blocking on production).

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

KEYS *

Output Example

Console / Terminal
OK
DEL key
Permanently delete a specified key and its associated value.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

DEL key

Output Example

Console / Terminal
OK

Strings

SET key value
Store a string value associated with a specified key.

When to Use

When storing or fetching standard string values, setting key timers, or configuring auto-expiration TTLs.

Common Mistakes

Forgetting that updating a key with SET will overwrite and clear any previously configured EXPIRE TTL timer.

Shortcut / Pro-Tip

Use TTL command to inspect how many seconds are left before a cached key expires.

Example

SET key value

Output Example

Console / Terminal
OK
GET key
Retrieve the string value mapped to a key.

When to Use

When storing or fetching standard string values, setting key timers, or configuring auto-expiration TTLs.

Common Mistakes

Forgetting that updating a key with SET will overwrite and clear any previously configured EXPIRE TTL timer.

Shortcut / Pro-Tip

Use TTL command to inspect how many seconds are left before a cached key expires.

Example

GET key

Output Example

Console / Terminal
OK
INCR key
Increment the numeric value of a key by 1 (atomic operation).

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

INCR key

Output Example

Console / Terminal
OK
DECR key
Decrement the numeric value of a key by 1.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

DECR key

Output Example

Console / Terminal
OK

Hashes

HSET user:1 name "Alex" age 30
Set fields and values on a Redis hash mapping.

When to Use

When storing or fetching standard string values, setting key timers, or configuring auto-expiration TTLs.

Common Mistakes

Forgetting that updating a key with SET will overwrite and clear any previously configured EXPIRE TTL timer.

Shortcut / Pro-Tip

Use TTL command to inspect how many seconds are left before a cached key expires.

Example

HSET user:1 name "Alex" age 30

Output Example

Console / Terminal
OK
HGET user:1 name
Retrieve the value of a specific field within a hash.

When to Use

When storing or fetching standard string values, setting key timers, or configuring auto-expiration TTLs.

Common Mistakes

Forgetting that updating a key with SET will overwrite and clear any previously configured EXPIRE TTL timer.

Shortcut / Pro-Tip

Use TTL command to inspect how many seconds are left before a cached key expires.

Example

HGET user:1 name

Output Example

Console / Terminal
OK
HGETALL user:1
Retrieve all fields and values stored in a specific hash.

When to Use

When storing or fetching standard string values, setting key timers, or configuring auto-expiration TTLs.

Common Mistakes

Forgetting that updating a key with SET will overwrite and clear any previously configured EXPIRE TTL timer.

Shortcut / Pro-Tip

Use TTL command to inspect how many seconds are left before a cached key expires.

Example

HGETALL user:1

Output Example

Console / Terminal
OK

Lists

LPUSH mylist "first"
Prepend an element to the left (head) of a list.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

LPUSH mylist "first"

Output Example

Console / Terminal
OK
RPUSH mylist "last"
Append an element to the right (tail) of a list.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

RPUSH mylist "last"

Output Example

Console / Terminal
OK
LPOP mylist
Remove and return the first element from the left of the list.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

LPOP mylist

Output Example

Console / Terminal
OK
LRANGE mylist 0 -1
Retrieve a range of elements from a list (0 to -1 fetches all).

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

LRANGE mylist 0 -1

Output Example

Console / Terminal
OK

Sets & Sorted Sets

SADD myset "member"
Add a member to an unordered unique set.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

SADD myset "member"

Output Example

Console / Terminal
OK
SISMEMBER myset "member"
Determine if a member belongs to a specific set.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

SISMEMBER myset "member"

Output Example

Console / Terminal
OK
ZADD highscores 500 "player1"
Add a member with a score to a sorted set.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

ZADD highscores 500 "player1"

Output Example

Console / Terminal
OK
ZRANGE highscores 0 -1 WITHSCORES
Retrieve members and scores sorted from lowest to highest.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

ZRANGE highscores 0 -1 WITHSCORES

Output Example

Console / Terminal
OK

Server Admin

PING
Ping the server to verify the database connection is alive (returns PONG).

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

PING

Output Example

Console / Terminal
OK
FLUSHDB
Permanently delete all keys stored in the currently selected database index.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

FLUSHDB

Output Example

Console / Terminal
OK
MONITOR
Stream and audit all commands received by the Redis server in real-time.

When to Use

When managing extreme-throughput cache buffers, transient session stores, atomic counters, or real-time pub/sub pipelines.

Common Mistakes

Running slow, linear pattern-matching commands like KEYS * in active production databases, halting the single-threaded CPU loop.

Shortcut / Pro-Tip

Use SCAN instead of KEYS to iterate through keys incrementally without blocking other concurrent commands.

Example

MONITOR

Output Example

Console / Terminal
OK

Redis Best Practices

1Establish Clear Key Naming Patterns

Use colon-delimited names to structure key paths logically (e.g., object:id:attribute like 'user:1000:profile') for easy search and organization.

2Set TTLs on Caching Keys

Always specify expiration timers (TTL) on cache entries to prevent stale data accumulation and manage memory capacity automatically.

3Utilize Connection Pooling

Reuse connections through client pools rather than opening and closing TCP connections for every database query.

4Batch Queries with Pipelining

Group multiple commands into a single round-trip pipeline to minimize network latency overhead.

5Keep Memory Utilization under Control

Configure eviction policies (like volatile-lru or allkeys-lru) so the server handles out-of-memory states predictably.

Common Redis Errors & Solutions

Error

OOM command not allowed when used memory > 'maxmemory'

Solution

Redis has filled up its allocated RAM and the active eviction policy cannot free any space. Solution: Increase MaxMemory settings, or optimize key expirations.

Error

WRONGTYPE Operation against a key holding the wrong kind of value

Solution

Applying a command to an incompatible data structure (e.g. running HGET on a String key). Solution: Verify key type using the 'TYPE <key>' command first.

Error

KEYS command timed out / locked database

Solution

Running 'KEYS *' on large production databases blocks the single-threaded CPU loop. Solution: Transition all search queries to use the non-blocking SCAN command.

Error

NOAUTH Authentication required

Solution

The server has pass protection active but no password was sent. Solution: Run 'AUTH <password>' prior to executing data commands.

Error

Connection refused

Solution

The redis-cli client is unable to establish a port link. Solution: Verify that the Redis daemon is running and bound to correct host IPs/ports.

Common Redis Interview Questions

Q1What is Redis and what is its primary use case?

Redis (Remote Dictionary Server) is an open-source, in-memory key-value data store used primarily as a database, cache, message broker, and queue, known for sub-millisecond response latencies.

Q2What are some data structures supported by Redis?

Redis supports Strings, Hashes, Lists, Sets, Sorted Sets (with range queries), Bitmaps, HyperLogLogs, Geospatial indexes, and Streams.

Q3How does Redis handle data persistence?

Redis offers two main persistence options: RDB (Redis Database) which takes point-in-time snapshots of your dataset at specified intervals, and AOF (Append Only File) which logs every write command received by the server.

Q4What is Redis Sentinel?

Redis Sentinel is a system designed to manage Redis instances. It handles high-availability monitoring, automatic failover of a master server to a replica, and client service discovery configuration.

Q5How does a Redis Hash differ from a standard String key-value?

A Redis Hash is an object structure containing field-value pairs, which is highly efficient for representing flat user profiles or models, saving memory overhead compared to single JSON string keys.