Databases 4 min read

Master Redis CLI: Essential Commands for Managing Keys, Backups, and Restoration

Learn how to connect to Redis using redis-cli, select databases, list and manipulate keys, retrieve values, check database size, view server info, and perform full backups and restores, with clear command examples for each operation.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Redis CLI: Essential Commands for Managing Keys, Backups, and Restoration

1. Connect

./redis-cli -h 127.0.0.1 -p 6379 -a admin@2020

-h redis host address

-a redis password

-p redis port

2. Select Database (0‑15)

127.0.0.1:6379[3]> select 3
OK

3. View All Keys

127.0.0.1:6379[3]> keys *
1) "systemSetting:settingKey"
2) "license_count:sync"
3) "serviceHub:editing"

4. Get Value of a Key

get key

5. Delete One or Multiple Keys

del key key2

6. Count Keys in Current Database

127.0.0.1:6379> select 3
OK
127.0.0.1:6379> dbsize
(integer) 3

7. Retrieve Redis Server Information

info

8. List All Databases and Key Statistics

127.0.0.1:6379[3]> info keyspace
# Keyspace
db1:keys=85,expires=85,avg_ttl=36119200
db2:keys=31,expires=3,avg_ttl=7267446
db3:keys=3,expires=1,avg_ttl=90056850
db4:keys=2,expires=0,avg_ttl=0
db5:keys=3,expires=1,avg_ttl=1137909600
db6:keys=333,expires=53,avg_ttl=46104293
db8:keys=78,expires=35,avg_ttl=3336299907

9. Get Total Number of Keys in a Database

127.0.0.1:6379> select 3
OK
127.0.0.1:6379> dbsize
(integer) 3

Backup and Restore

Full Backup

redis-cli -a admin@2020 save

Full Data Restore

Stop Redis, move the backup file dump.rdb to the Redis installation directory, then restart the Redis server to restore the data.

# Get data directory
127.0.0.1:6379> CONFIG GET dir
1) "dir"
2) "/data"
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CLIredisDatabase ManagementRestoreKey Operations
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.