How to List All Redis Databases?
Asked Answered
P

4

279

I ran this command to access my redis server.

telnet 127.0.0.1 6379

What is the command to show all of my databases?

Pulverize answered 9/10, 2012 at 14:50 Comment(1)
Four decades of IT history in one line (client from 1969, server from 2009).Thermoluminescence
O
492

There is no command to do it (like you would do it with MySQL for instance). The number of Redis databases is fixed, and set in the configuration file. By default, you have 16 databases. Each database is identified by a number (not a name).

You can use the following command to know the number of databases:

CONFIG GET databases
1) "databases"
2) "16"

You can use the following command to list the databases for which some keys are defined:

INFO keyspace
# Keyspace
db0:keys=10,expires=0
db1:keys=1,expires=0
db3:keys=1,expires=0

Please note that you are supposed to use the "redis-cli" client to run these commands, not telnet. If you want to use telnet, then you need to run these commands formatted using the Redis protocol.

For instance:

*2
$4
INFO
$8
keyspace

$79
# Keyspace
db0:keys=10,expires=0
db1:keys=1,expires=0
db3:keys=1,expires=0

You can find the description of the Redis protocol here: http://redis.io/topics/protocol

Obligato answered 9/10, 2012 at 17:35 Comment(2)
Thanks for introducing to the Redis protocol along the way..Catalog
CONFIG GET doesn't work for me but INFO keyspace doesCrashaw
A
102

Or you can just run the following command and you will see all databases of the Redis instance without firing up redis-cli:

$ redis-cli INFO | grep ^db
db0:keys=1500,expires=2
db1:keys=200000,expires=1
db2:keys=350003,expires=1
Arabesque answered 15/11, 2012 at 14:6 Comment(3)
But the same could be achieved with redis-cli INFO keyspaceMohammedmohammedan
Downvoting because this is fragile, is likely to break in future releases, and because there is a built in command (as mentioned) to achieve the same result.Deckhand
Beware of false negatives when used with wrong search strings, e.g. $ redis-cli INFO | grep ^db.veri.bad. Prefer $ redis-cli INFO keyspaceThermoluminescence
S
52

you can use redis-cli INFO keyspace

localhost:8000> INFO keyspace
# Keyspace
db0:keys=7,expires=0,avg_ttl=0
db1:keys=1,expires=0,avg_ttl=0
db2:keys=1,expires=0,avg_ttl=0
db11:keys=1,expires=0,avg_ttl=0
Stilt answered 30/11, 2019 at 12:0 Comment(0)
T
1

Perhaps the most memorable and definitely the most complete way, with #Keyspaces section displayed conveniently at the end:

$ redis-cli info

And if you set the password (e.g. with an env var. called REDIS_PASS), pass it to the -a (auth) arg:

$ redis-cli -a $REDIS_PASS info
Thermoluminescence answered 29/10, 2022 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.