Home > Database > Redis > body text

How many libraries does redis have?

anonymity
Release: 2019-06-05 10:11:17
Original
7316 people have browsed it

Redis is a dictionary-structured storage server. In fact, a Redis instance provides multiple dictionaries for storing data. The client can specify which dictionary to store the data in. This is similar to the well-known fact that multiple databases can be created in a relational database instance, so each dictionary can be understood as an independent database.

How many libraries does redis have?

Each database is named externally with an increasing number starting from 0. Redis supports 16 databases by default (more can be supported through configuration files, no upper limit), you can Modify this number by configuring databases. After the client establishes a connection with Redis, it will automatically select database No. 0, but you can use the SELECT command to change the database at any time. If you want to select database No. 1:

redis> SELECT 1
OK
redis [1] > GET foo
(nil)
Copy after login

However, these databases named with numbers are different from the databases we understand. There is a difference. First of all, Redis does not support custom database names. Each database is named after a number. Developers must record which databases store which data. In addition, Redis does not support setting different access passwords for each database, so a client can either access all databases or not have permission to access even one database. The most important point is that multiple databases are not completely isolated. For example, the FLUSHALL command can clear the data in all databases in a Redis instance. To sum up, these databases are more like namespaces and are not suitable for storing data from different applications. For example, you can use database No. 0 to store data in the production environment of an application, and use database No. 1 to store data in the test environment. However, it is not appropriate to use database No. 0 to store the data of application A and use database No. 1 to store the data of application B. It is different. Applications should use different Redis instances to store data. Since Redis is very lightweight, an empty Redis instance only takes up about 1M, so there is no need to worry about multiple Redis instances taking up a lot of additional memory.

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:

 /etc/redis/redis.conf
Copy after login

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

The above is the detailed content of How many libraries does redis have?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!