Almost 200 redis instances were opened on one server, and it crashed just looking at it. This is nothing more than trying to keep different types of data belonging to different applications separate from each other.
So, is there any way in redis to keep different application data separate from each other while being stored on the same instance? It is equivalent to a mysql database. Different application data are stored in different databases.
Under redis, the database is identified by an integer index rather than 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:
databases 16
You can switch to a different database through the following commands
redis> select 2 OK
Subsequently, all commands will use database 3 until you Explicitly switch to another database.
Each database has its own space, so there is no need to worry about key conflicts between them.
Under different databases, the same key gets its own value.
flushdb command to clear data will only clear the data in the current database and will not affect other databases.
#Theflushall command will clear the data of this instance. Be extremely careful before executing this command.
The number of databases is configurable, and the default is 16. Modify the databases directive under redis.conf:
databases 64
redis does not provide any method to associate and identify different databases. Therefore, you are required to keep track of what data is stored in which database.
Therefore, the above scenario of quickly opening 200 instances can be stored in different databases without having to open so many instances.
For more redis knowledge, please pay attention to the redis introductory tutorial column.
The above is the detailed content of Use of redis multiple databases. For more information, please follow other related articles on the PHP Chinese website!