Is there any command in Redis to get the database name that I am using right now? I know select is to switch the database. I am looking for "get database name" kind of a command.
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).
Redis databases are numbered from 0 to 15 and, by default, you connect to database 0 when you connect to your Redis instance. However, you can change the database you're using with the select command after you connect: select 15.
The Redis configuration file is located at installdir/redis/etc/redis.
Databases. Out of the box, every Redis instance supports 16 databases. The database index is the number you see at the end of a Redis URL: redis://localhost:6379/0 . The default database is 0 but you can change that to any number from 0-15 (and you can configure Redis to support more databases, look in redis.
First of all, there's NO name for Redis database. Instead, it has an index.
You can use the CLIENT SETNAME
and CLIENT LIST
commands to get the database index dynamically:
CLIENT SETNAME a-unique-name
to set a unique name for the current connection.CLIENT LIST
to get info of all clients that connecting to Redis.You can get the format of client info from the doc.
NOTE: If anyone has a simpler solution, please let me know :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With