background

In practical projects redis is often used for caching, distributed locks/message queues, etc. However, after setting up and configuring the Redis server, many friends will find and have such questions. Why redis has set up 16 databases by default?

The origin of 16 databases

Redis is a dictionary structured storage server. A single redis instance provides multiple dictionaries for storing data. Clients can specify which dictionaries to store data in. This is similar to creating multiple databases in a relational database instance, so each dictionary in it can be understood as a separate database. Redis supports 16 databases by default. You can modify databases in the redis/redis.conf file to change the value. The client selects database 0 by default after linking to Redis, but can change the database at any time using the select command. SQL > alter database; Go to 1127.0.0.1:6379> SELECT 1ok127.0.0.1:6379 [1]>127.0.0.1:6379[1]># go to 0127.0.0.1:6379[1]> SELECT 0ok127.0.0.1:6379 ># Get username127.0.0.1:6379[1]> get username from library 1. In a real project, you can specify the database as a redis configuration file

Does clustering support multiple dB’s for an instance?

All of the above is based on single Redis. The select command is not supported to switch db in cluster mode because redis cluster mode has only one DB0.

The public account @UP technology control