Redis Persistence, Replication, and Cluster Cheat Sheet

RDB, AOF, replication, failover, Lua scripts, functions, and cluster command references for operational Redis use.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Persistence
Read time of last successful save
LASTSAVE

# Return the Unix timestamp of last successful save.

Rewrite AOF in background
BGREWRITEAOF

# Compact the append-only file in the background.

Wait for replicas to acknowledge writes
WAIT 1 5000

# Block until writes reach a minimum number of replicas or timeout.

Wait for local AOF fsync
WAITAOF 1 1000 5000

# Wait for AOF persistence conditions when supported.

## Replication and failover
Make server replicate from a primary
REPLICAOF 10.0.0.10 6379

# Turn the current node into a replica of a primary.

Promote a replica
REPLICAOF NO ONE

# Stop replicating and promote current node to primary.

Inspect node role
ROLE

# Return whether this node is primary, replica, or sentinel and related metadata.

Trigger coordinated failover
FAILOVER

# Ask a primary to hand off leadership to a replica.

Partial resynchronization handshake
PSYNC ? -1

# Replication handshake command used internally by replicas.

## Lua scripts and functions
Run a Lua script
EVAL "return redis.call('GET', KEYS[1])" 1 user:1:name

# Execute Lua server-side atomically.

Run a cached Lua script by SHA
EVALSHA <sha1> 1 user:1:name

# Execute a previously loaded Lua script.

Load a Lua script
SCRIPT LOAD "return 1"

# Cache a Lua script and return its SHA1.

Check cached scripts
SCRIPT EXISTS <sha1>

# Check whether one or more scripts are cached.

Clear cached scripts
SCRIPT FLUSH

# Remove all cached Lua scripts.

Load a Redis function library
FUNCTION LOAD "#!lua name=mylib
redis.register_function('ping', function() return 'pong' end)"

# Load a function library into the server.

List loaded function libraries
FUNCTION LIST

# Inspect currently loaded libraries and functions.

Call a registered function
FCALL ping 0

# Execute a loaded Redis function.

Delete a function library
FUNCTION DELETE mylib

# Remove a loaded function library.

## Cluster basics
Inspect cluster state
CLUSTER INFO

# Read cluster state, slot coverage, and message counters.

List cluster nodes
CLUSTER NODES

# Show known cluster nodes and flags.

Inspect slot mapping
CLUSTER SLOTS

# Return slot-to-node ownership information.

Compute key hash slot
CLUSTER KEYSLOT user:{42}:profile

# Compute the cluster slot for a key.

Count keys in a slot
CLUSTER COUNTKEYSINSLOT 1234

# Count how many keys exist in one slot.

Allow replica reads in cluster mode
READONLY

# Tell a cluster replica connection to serve reads.

Return to normal read/write routing
READWRITE

# Disable READONLY mode on a cluster connection.

Accept an ASK redirection
ASKING

# Send ASKING before a redirected command during slot migration.

Recommended next

No recommendations yet.