PASSWORD RESET

Your destination for complete Tech news

How to list all databases in Redis?

9.44K 0
< 1 min read

Redis uses a database model in which you can select a database using the SELECT command. By default, Redis has 16 databases numbered from 0 to 15.

To list all the databases in Redis, you can use the “INFO” command along with “keyspace”.

$ redis-cli INFO keyspace

This command will return the information about all the databases, the output will be like:

db0:keys=2,expires=0
db1:keys=3,expires=0
db2:keys=1,expires=0

In python redis library

import redis
r = redis.Redis()
dbs = r.info("keyspace")

This will return a dictionary containing the information of all the databases.

Please note that the number of databases in Redis can be set in the configuration file, but the default is 16, and you can switch between them using the SELECT command by specifying the database number.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.