In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
The purpose of this article is to share with you the reasons why redis has set up 16 databases by default. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
In the actual development work, we usually use redis database for caching, distributed locks / message queues, and so on. But we usually have the question of why 16 databases are set up by default after setting up and configuring the redis server.
Next, let's introduce this question to you.
I. the origin of 16 databases
Redis is a dictionary-structured storage server, and a redis instance provides multiple dictionaries for storing data, and the client can specify which dictionary to store the data in. This is similar to creating multiple databases in a relational database instance (as shown in the following figure), each of which can be understood as a separate database.
Redis supports 16 databases by default. You can modify this value by adjusting the databases in redis's configuration file redis/redis.conf. After setting it, restart redis to complete the configuration.
After the client establishes a link with redis, database 0 is selected by default, but the database can be replaced at any time using the select command.
# switch database operation: switch to 1127.0.0.1 SELECT 1OK127.0.0.1:6379 [1] > 127.0.0.1 username127.0.0.1:6379 6379 [1] > # switch to 0127.0.0.1 username127.0.0.1:6379 6379 [1] > SELECT 0OK127.0.0.1:6379 > # get username127.0.0.1:6379 [1] > get username from Library 1.
(learn video sharing: redis video tutorial)
In an actual project, you can specify the database in the form of a redis configuration file, as shown in the following figure
Second, correctly understand the concept of "database" of redis.
Because redis does not support custom database names, all databases are named by numbers. Developers need to record the corresponding relationship between the stored data and the database. In addition, redis does not support setting a different access password for each database, all clients can either access all databases, or all databases do not have permission to access. To correctly understand the "database" concept of redis, you have to mention a command:
Clear data from all databases in the redis instance
127.0.0.1 purl 6379 > FLUSH ALL
Emptying data in one redis database does not empty data in other libraries.
127.0.0.1 purl 6379 > FLUSH db0
This command clears all database data under the instance, which is different from the relational database that we are familiar with. Multiple libraries in a relational database are often used to store data from different applications, and there is no way to empty all library data under an instance at the same time. All of these db are more like namespaces for redis and are not suitable for storing data from different applications. For example, database 0 can be used to store data in the development environment, and database 1 can be used to store data in the test environment, but it is not suitable to use database 0 to store data from application An and database 1 to store data from application B. different environments should use different redis instances to store data. Redis is very lightweight, and an empty redis instance takes up only about 1m, so you don't have to worry about multiple redis instances taking up a lot of extra memory.
3. Does it support multiple db for one instance in the case of a cluster?
All of the above is based on the case of single redis. Using the select command to switch db is not supported in the case of cluster, because there is only one db0 in redis cluster mode.
Thank you for reading! This is the end of this article on "the reason why redis sets up 16 databases by default". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.