FreeTool
Developer Tools

Redis Cheat Sheet

Searchable reference for 200+ Redis commands — strings, hashes, lists, sets, sorted sets, pub/sub, streams, Lua scripting, cluster, ACL, and cli tips with one-click copy

Connection & Server18Strings20Keys & Expiry19Hashes13Lists18Sets18Sorted Sets20Pub/Sub & Streams18Transactions & Scripting12Persistence & Replication11ACL & Security11Cluster & Sentinel13HyperLogLog, Bitmap & Geo13Maintenance & Debugging13redis-cli Tips12
redis-cli

Connect to local Redis server

redis-cli -h host -p 6379 -a password

Connect to remote Redis with auth

redis-cli --tls -h host -p 6380

Connect with TLS encryption

PING

Test connection (returns PONG)

AUTH password

Authenticate to the server

AUTH username password

Authenticate with ACL username (Redis 6+)

SELECT 0

Switch to database 0 (0-15)

QUIT

Close the connection

INFO

Get server info and statistics

INFO memory

Get memory usage info

CONFIG GET *

Get all configuration parameters

CONFIG SET maxmemory 256mb

Set a configuration parameter at runtime

DBSIZE

Return the number of keys in current DB

TIME

Return server time (seconds + microseconds)

CLIENT LIST

List all connected clients

CLIENT SETNAME myapp

Set a name for the current connection

SLOWLOG GET 10

Get last 10 slow queries

MONITOR

Stream all commands received by server (debug)

SET key valueO(1)

Set a key to a string value

SET key value EX 60

Set with expiry in seconds

SET key value PX 60000

Set with expiry in milliseconds

SET key value NX

Set only if key does NOT exist (create)

SET key value XX

Set only if key already EXISTS (update)

SETNX key value

Set if not exists (returns 1 or 0)

GET keyO(1)

Get the value of a key

GETDEL key

Get value and delete the key (Redis 6.2+)

GETSET key newvalue

Set new value and return old value

MSET key1 val1 key2 val2O(N)

Set multiple keys at once

MGET key1 key2 key3O(N)

Get multiple values at once

APPEND key value

Append to existing string value

STRLEN key

Get length of the string value

INCR keyO(1)

Increment integer value by 1

INCRBY key 5

Increment by specific integer

INCRBYFLOAT key 1.5

Increment by float value

DECR key

Decrement integer value by 1

DECRBY key 5

Decrement by specific integer

GETRANGE key 0 3

Get substring (inclusive range)

SETRANGE key 0 "Hello"

Overwrite part of string at offset

KEYS pattern*

Find all keys matching pattern

⚠️ Don't use in production — use SCAN

SCAN 0 MATCH user:* COUNT 100O(1) per call

Iterate keys safely with cursor

EXISTS key

Check if key exists (returns 0 or 1)

TYPE key

Get the type of a key

RENAME key newkey

Rename a key

RENAMENX key newkey

Rename only if newkey doesn't exist

DEL key1 key2O(N)

Delete one or more keys (blocking)

UNLINK key1 key2

Delete keys asynchronously (non-blocking)

EXPIRE key 60

Set TTL in seconds

PEXPIRE key 60000

Set TTL in milliseconds

EXPIREAT key 1700000000

Set expiry at Unix timestamp

TTL key

Get remaining TTL in seconds (-1 = no expiry, -2 = doesn't exist)

PTTL key

Get remaining TTL in milliseconds

PERSIST key

Remove expiry (make key permanent)

OBJECT ENCODING key

Get the internal encoding of a key

OBJECT IDLETIME key

Get seconds since key was last accessed

DUMP key

Serialize a key's value

RESTORE key 0 "\x00..."

Deserialize and restore a key

RANDOMKEY

Return a random key from the DB

HSET user:1 name "Alice" age 30O(N)

Set one or more hash fields

HGET user:1 nameO(1)

Get a single hash field value

HMGET user:1 name age email

Get multiple hash field values

HGETALL user:1O(N)

Get all fields and values

HDEL user:1 email

Delete one or more hash fields

HEXISTS user:1 name

Check if hash field exists

HKEYS user:1

Get all field names

HVALS user:1

Get all field values

HLEN user:1

Get number of fields in hash

HINCRBY user:1 age 1

Increment hash field integer by N

HINCRBYFLOAT user:1 score 0.5

Increment hash field by float

HSETNX user:1 email "a@b.com"

Set field only if it doesn't exist

HSCAN user:1 0 MATCH name* COUNT 10

Iterate hash fields with cursor

LPUSH mylist a b cO(N)

Push elements to the head (left)

RPUSH mylist x y z

Push elements to the tail (right)

LPOP mylistO(1)

Remove and return from head

RPOP mylist

Remove and return from tail

LPOP mylist 3

Pop N elements from head (Redis 6.2+)

LRANGE mylist 0 -1O(S+N)

Get all elements (0 to last)

LRANGE mylist 0 9

Get first 10 elements

LLEN mylistO(1)

Get the length of the list

LINDEX mylist 0

Get element at index

LSET mylist 0 newvalue

Set element at index

LINSERT mylist BEFORE pivot value

Insert before a pivot element

LINSERT mylist AFTER pivot value

Insert after a pivot element

LREM mylist 2 value

Remove N occurrences of value

LTRIM mylist 0 99

Trim list to range (keep 0-99)

RPOPLPUSH src dst

Pop from src tail, push to dst head

LMOVE src dst LEFT RIGHT

Move element between lists (Redis 6.2+)

BLPOP mylist 5

Blocking pop from head (5s timeout)

Great for job queues

BRPOP mylist 5

Blocking pop from tail (5s timeout)

SADD myset a b cO(N)

Add members to a set

SREM myset a

Remove members from a set

SMEMBERS mysetO(N)

Get all members

SISMEMBER myset aO(1)

Check if member exists

SMISMEMBER myset a b c

Check multiple members (Redis 6.2+)

SCARD mysetO(1)

Get number of members (cardinality)

SPOP myset

Remove and return random member

SPOP myset 3

Remove and return N random members

SRANDMEMBER myset

Get random member (without removing)

SRANDMEMBER myset 3

Get N random members

SUNION set1 set2

Union of two or more sets

SUNIONSTORE dest set1 set2

Store union result in dest

SINTER set1 set2

Intersection of sets

SINTERSTORE dest set1 set2

Store intersection in dest

SDIFF set1 set2

Difference of sets (in set1 but not set2)

SDIFFSTORE dest set1 set2

Store difference in dest

SMOVE src dst member

Move member from one set to another

SSCAN myset 0 MATCH a* COUNT 10

Iterate set members with cursor

ZADD leaderboard 100 alice 200 bobO(log N)

Add members with scores

ZADD leaderboard NX 100 charlie

Add only if member doesn't exist

ZADD leaderboard XX 150 alice

Update only if member exists

ZADD leaderboard GT 300 alice

Update only if new score > current (Redis 6.2+)

ZSCORE leaderboard aliceO(1)

Get score of a member

ZRANK leaderboard alice

Get rank (0-based, low to high)

ZREVRANK leaderboard alice

Get rank (0-based, high to low)

ZINCRBY leaderboard 10 alice

Increment score of a member

ZRANGE leaderboard 0 -1 WITHSCORES

Get all members sorted low→high

ZREVRANGE leaderboard 0 9 WITHSCORES

Top 10 members (high→low)

ZRANGEBYSCORE leaderboard 100 200

Get members with scores in range

ZRANGEBYSCORE leaderboard -inf +inf LIMIT 0 10

Paginated score range query

ZCARD leaderboard

Get number of members

ZCOUNT leaderboard 100 200

Count members with scores in range

ZREM leaderboard alice

Remove members

ZREMRANGEBYSCORE leaderboard 0 100

Remove members by score range

ZREMRANGEBYRANK leaderboard 0 2

Remove members by rank range

ZUNIONSTORE dest 2 set1 set2 WEIGHTS 1 2

Union sorted sets with weights

ZINTERSTORE dest 2 set1 set2

Intersect sorted sets

ZSCAN leaderboard 0 MATCH a* COUNT 10

Iterate sorted set with cursor

SUBSCRIBE channel1 channel2

Subscribe to channels

PSUBSCRIBE news.*

Subscribe with pattern matching

PUBLISH channel1 "Hello!"

Publish a message to a channel

UNSUBSCRIBE channel1

Unsubscribe from a channel

PUBSUB CHANNELS

List active channels

PUBSUB NUMSUB channel1

Count subscribers for a channel

XADD stream * field value

Add entry to stream (auto ID)

Streams (Redis 5+)

XADD stream MAXLEN ~ 1000 * f v

Add with approximate max length cap

XLEN stream

Get number of entries in stream

XRANGE stream - +

Read all stream entries

XRANGE stream - + COUNT 10

Read first 10 entries

XREVRANGE stream + - COUNT 10

Read last 10 entries (reverse)

XREAD COUNT 5 BLOCK 0 STREAMS stream 0

Read new entries (blocking)

XGROUP CREATE stream grp $ MKSTREAM

Create consumer group

XREADGROUP GROUP grp consumer COUNT 5 BLOCK 0 STREAMS stream >

Read as consumer group member

XACK stream grp id1 id2

Acknowledge processed entries

XPENDING stream grp

Show pending entries summary

XTRIM stream MAXLEN 1000

Trim stream to max length

MULTI

Start a transaction block

EXEC

Execute all commands in transaction

DISCARD

Discard all commands in transaction

WATCH key

Watch key for changes (optimistic lock)

UNWATCH

Unwatch all keys

EVAL "return redis.call('GET',KEYS[1])" 1 key

Run Lua script

EVALSHA sha1 1 key

Run cached Lua script by SHA1

SCRIPT LOAD "return 1"

Load script and return SHA1 hash

SCRIPT EXISTS sha1

Check if script is cached

SCRIPT FLUSH

Remove all cached scripts

FUNCTION LOAD "#!lua name=mylib\nredis.register_function('myfunc', function(keys, args) return 'ok' end)"

Load a Redis Function (Redis 7+)

FCALL myfunc 0

Call a loaded Redis Function

SAVE

Synchronous RDB snapshot (blocking!)

⚠️ Blocks server

BGSAVE

Background RDB snapshot

BGREWRITEAOF

Background AOF rewrite

LASTSAVE

Timestamp of last successful save

CONFIG SET save "900 1 300 10"

Set RDB auto-save rules

CONFIG SET appendonly yes

Enable AOF persistence

CONFIG SET appendfsync everysec

AOF fsync policy (always/everysec/no)

REPLICAOF host 6379

Make this server a replica of another

REPLICAOF NO ONE

Promote replica to primary

INFO replication

Get replication status

WAIT 1 5000

Wait for N replicas to acknowledge writes

ACL LIST

List all ACL rules

ACL GETUSER default

Get ACL rules for a user

ACL SETUSER alice on >pass ~key:* +get +set

Create user with specific permissions

ACL SETUSER alice off

Disable a user

ACL DELUSER alice

Delete a user

ACL WHOAMI

Show current authenticated username

ACL CAT

List all command categories

ACL CAT read

List commands in a category

ACL LOG 10

Show last 10 ACL denial events

ACL SAVE

Save ACL rules to file

ACL LOAD

Reload ACL rules from file

CLUSTER INFO

Get cluster state info

CLUSTER NODES

List all cluster nodes

CLUSTER MEET host 6379

Add a node to the cluster

CLUSTER ADDSLOTS 0 1 2 ... 5460

Assign hash slots to this node

CLUSTER REPLICATE node-id

Make this node a replica

CLUSTER FAILOVER

Manual failover (replica → primary)

CLUSTER RESET

Reset cluster configuration

CLUSTER KEYSLOT key

Get the hash slot for a key

CLUSTER SLOTS

Get cluster slot mapping

redis-cli --cluster create host1:6379 host2:6379 host3:6379 --cluster-replicas 1

Create a new cluster

SENTINEL MASTERS

List monitored masters (Sentinel)

SENTINEL GET-MASTER-ADDR-BY-NAME mymaster

Get current master address

SENTINEL FAILOVER mymaster

Force failover (Sentinel)

PFADD visitors user1 user2 user3

Add elements to HyperLogLog

PFCOUNT visitors

Get approximate cardinality

PFMERGE dest hll1 hll2

Merge HyperLogLogs

SETBIT mybit 7 1

Set bit at offset

GETBIT mybit 7

Get bit at offset

BITCOUNT mybit

Count bits set to 1

BITOP AND dest key1 key2

Bitwise AND between keys

BITPOS mybit 1

Find first bit set to 1

GEOADD locations 13.361 38.115 "Palermo"

Add geospatial point

GEODIST locations Palermo Catania km

Distance between two points

GEOSEARCH locations FROMMEMBER Palermo BYRADIUS 100 km ASC

Search within radius

GEOPOS locations Palermo

Get coordinates of a member

GEOHASH locations Palermo

Get Geohash string

FLUSHDB

Delete all keys in current database

⚠️ Destructive!

FLUSHDB ASYNC

Delete all keys asynchronously

FLUSHALL

Delete all keys in ALL databases

⚠️ Very destructive!

DEBUG SLEEP 5

Pause the server for 5 seconds (debug)

DEBUG OBJECT key

Show internal encoding info for key

MEMORY USAGE key

Estimate memory usage of a key in bytes

MEMORY DOCTOR

Get memory usage advice

OBJECT HELP

Show OBJECT subcommand help

OBJECT FREQ key

Get access frequency (LFU policy)

LATENCY LATEST

Show latest latency events

LATENCY HISTORY event

Show latency history for an event

SHUTDOWN SAVE

Save and shut down the server

SHUTDOWN NOSAVE

Shut down without saving

redis-cli --scan --pattern 'user:*'

Scan keys matching pattern from CLI

redis-cli --bigkeys

Find biggest keys in the database

redis-cli --memkeys

Sample keys and report memory usage

redis-cli --hotkeys

Find hottest keys (requires LFU)

redis-cli --stat

Live stats (ops/sec, memory, clients)

redis-cli --latency

Measure latency to server continuously

redis-cli --latency-history

Latency with 15s interval history

redis-cli --pipe < commands.txt

Mass import with Redis protocol

redis-cli --rdb dump.rdb

Download RDB snapshot from remote

redis-cli --csv LRANGE mylist 0 -1

Output in CSV format

redis-cli --json INFO memory

Output in JSON format (Redis 7+)

redis-cli --eval script.lua key1 , arg1

Evaluate Lua script from file

229 Redis commands · hover any command to copy

Don't see what you need?

We build free tools based on community feedback. If there's a utility that would improve your workflow, suggest it today!

Redis Cheat Sheet — Free Online Tool | FreeTool24