How to switch databases under Redis

200 redis instances are almost opened on a server , and it crashes when it looks. This is nothing more than trying to separate different types of data from different applications.

 

So, is there any way for redis to separate different application data from each other and store them on the same instance? It is equivalent to the MySQL database , and different application data is stored in different databases.

Under redis, the database is identified by an integer index, not by a database name. By default, a client connects to database 0. The following parameters in the redis configuration file control the total number of databases:

 /etc/redis/redis.conf 

In the file, there is a configuration item databases = 16 // 16 databases by default

 

You can use the following command to switch to a different database

 

 

Subsequently, all commands will use database 3, knowing that you explicitly switch to another database.

 

Each database has its own space, don't worry about key conflicts.

 

In different databases, the same key gets its own value.

 

The flushdb command clears the data, which only clears the data in the current database, and does not affect other databases.

 

The flushall command will clear the data of this instance. Be very careful before executing this command.

 

The number of databases is configurable, by default it is 16. Modify the databases command under redis.conf:

 

Redis does not provide any method to associate and identify different databases. Therefore, you need to track what data is stored in which database.

Therefore, the above scenario of quickly opening 200 instances can be stored using different databases without having to open so many instances.

 

 

 

Configuration file can be configured

redis.port = Port
#
db redis.db = 3

发布了150 篇原创文章 · 获赞 149 · 访问量 81万+

Guess you like

Origin blog.csdn.net/chaishen10000/article/details/103394214