Home  >  Article  >  Database  >  How many default dbs does redis have?

How many default dbs does redis have?

anonymity
anonymityOriginal
2019-06-04 17:15:333777browse

Redis supports multiple databases, and the data of each database is isolated and cannot be shared, and is only available on a single machine. If it is a cluster, there is no concept of a database.

How many default dbs does redis have?

Redis is a dictionary-structured storage server. In fact, a Redis instance provides multiple dictionaries for storing data. The client can specify where to store the data. in the dictionary. 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.

Each database is externally named with an increasing number starting from 0. Redis supports 16 databases by default (more can be supported through configuration files, no upper limit), and this number can be modified 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)

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.

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

Statement:
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