Redis Common Commands - CodeSwordsman

High-frequency commands for connections, keys, the five data types, troubleshooting and replication, with blocking and flush warnings.

Redis 6.x / 7.xUpdated 2026-10-2934 commands

Connection & Info

Connect to an instance and enter the interactive shell

redis-cli -h 127.0.0.1 -p 6379

Connect with a password and suppress the plaintext warning

redis-cli -h 127.0.0.1 -p 6379 -a '<PASSWORD>' --no-auth-warning

The password stays in shell history; prefer the REDISCLI_AUTH env var

Test connectivity; returns PONG when healthy

redis-cli -h 127.0.0.1 -p 6379 ping

Show memory usage, fragmentation ratio and related metrics

redis-cli -h 127.0.0.1 -p 6379 info memory

Count the keys in the current database

redis-cli -h 127.0.0.1 -p 6379 dbsize

Key Management

Iterate keys in cursor batches without blocking the server

scan 0 match user:* count 100
Risky

Return every key at once and block the server when keys are many

keys *

Do not run in production; use SCAN or redis-cli --scan instead

Show the data type of a key

type user:1001

Show the remaining TTL; -1 means the key never expires

ttl session:abc

Set the key to expire in 3600 seconds

expire session:abc 3600

Delete a big key asynchronously to avoid blocking the main thread

unlink big:cache
Risky

Delete every key in the current database; this is unrecoverable

flushdb
Risky

Wipe all databases; never run it by accident in production

flushall

Data Types

Set a string value with a one-hour TTL

set user:1001:name "Tom" ex 3600

Atomically increment a counter such as page views

incr page:view

Set hash fields, which suits object storage

hset user:1001 name Tom age 28

Read all fields and values of a hash

hgetall user:1001

Push an element onto the left side of a list

lpush queue:jobs job1

Read all elements of a list

lrange queue:jobs 0 -1

Add unique members to a set

sadd tags:post:1 vue redis

Add a member with a score to a sorted set

zadd rank:score 98 tom

Return the top ten members by descending score

zrevrange rank:score 0 9 withscores

Troubleshooting

Show the last ten slow commands

slowlog get 10

Print every command the server receives in real time

monitor

Very verbose and slows the instance; stop it right after debugging

Show the memory used by a single key

memory usage user:1001

Scan the keyspace and list the biggest key of each type

redis-cli --bigkeys

Scans the whole keyspace; run it during off-peak hours

Persistence & Replication

Create an RDB snapshot in the background

bgsave

Change the RDB save policy at runtime

config set save "900 1 300 10"

In-memory only and lost on restart; run config rewrite to persist it

Turn this instance into a replica of the given master

replicaof 10.0.0.12 6379

Show replication role, offset and link status

info replication

Cluster

Show cluster state, slot coverage and node count

cluster info

List node roles, slot ranges and connection details

cluster nodes

Show which hash slot a key maps to

cluster keyslot user:1001

Check cluster config, slot coverage and consistency

redis-cli --cluster check 10.0.0.11:6379

Related tools

This website uses cookies to ensure you get the best experience on our website. Privacy Policy.