Home > Database > Redis > Use of redis multiple databases

Use of redis multiple databases

Release: 2020-05-09 09:06:19
forward
2256 people have browsed it

Use of redis multiple databases

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
Copy after login

You can switch to a different database through the following commands

redis> select 2
OK
Copy after login

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.

Use of redis multiple databases

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

Use of redis multiple databases

flushdb command to clear data will only clear the data in the current database and will not affect other databases.

Use of redis multiple 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
Copy after login

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!

Related labels:
source:ttlsa.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template