The database in Redis is not similar to the database in the Mysql database.

Database in Redis just provides namespace and isolation for grouping keys. It is partitioned and grouped under an index number.

For example, If you have 100000 keys and 20 databases.

Records from 0 to 5000 are stored in index 1, 5000 to 1000 in index 2, and so on up to 95000 to 100000 for index 20.

These names are just indexes that are configured in the Redis configuration file.

You will see the property databases in redis.conf file.

# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
databases 16

How to create a database in Redis

We can not create any new database in redis. Just use the created database names index.

Below are some of the commands

Command config gets databases used to know the count of a database

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

How to list out all databases in redis?

We can use the info keyspace command to list all databases and the number of keys for each database

127.0.0.1:6379> info keyspace
# Keyspace
db0:keys=1,expires=0,avg_ttl=0
db2:keys=1,expires=0,avg_ttl=0

Two databases contain keys that count as 1 and expire as never.

Or you can use the grep command with pipe to search ‘db’

redis-cli INFO | grep ^db

Redis database consumed memory

Maximum number of databases in redis

The default database is 16 in the Redis instance. The database provides a logically separated namespace for storing data.

It supports adding more databases in redis.conf, for example, you can change it to 30.

It just provides a namespace for grouping data, It is not designed to scale several databases.

The clients can access the namespace database, you can design the number of applications to easily save and flush the data always.

If you want millions of records to be saved, It is better to use more instances rather than a database count.