List All Redis Databases

匿名 (未验证) 提交于 2019-12-03 00:59:01

问题:

I ran this command to access my redis server.

telnet 127.0.0.1 6379 

Now, I want to show all of my databases.

Please tell me this command.

Thanks.

回答1:

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



回答2:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!