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.
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
OK3. 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 key5. Delete One or Multiple Keys
del key key26. Count Keys in Current Database
127.0.0.1:6379> select 3
OK
127.0.0.1:6379> dbsize
(integer) 37. Retrieve Redis Server Information
info8. 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=33362999079. Get Total Number of Keys in a Database
127.0.0.1:6379> select 3
OK
127.0.0.1:6379> dbsize
(integer) 3Backup and Restore
Full Backup
redis-cli -a admin@2020 saveFull 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"Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
