How to switch DB in Redis

Source: Internet
Author: User

200 Redis instances are turned on on a single server, and it crashes when you look at it. The only way to do this is to make different types of data belong to different applications and separate from each other.

So, isthere a way for Redis to keep different application data separate from each other and stored on the same instance? is equivalent to the MySQL database , different application data is stored under different databases.

Under Redis, a database is identified by an integer index, not by a database name. By default, one client connects to database 0. The following parameters in the Redis configuration file control the total number of databases:

/etc/redis/redis.conf file, there is a configuration entry databases = 16//default of 16 databases

You can switch to a different database by using the following command

Subsequently, all commands will use database 3, knowing that you explicitly switch to another database.

Each database has its own space, and there is no need to worry about key conflicts.

Under different databases, the same key is taken to the respective value.

The FLUSHDB command clears the data and clears only the data under the current database, without affecting other databases.

The Flushall command clears the data for this instance. Take extra care before executing this command.

The number of databases is configurable and is 16 by default. Modify the Databases directive under redis.conf:

Redis does not provide any way to correlate the identities of different databases. Therefore, you need to keep track of what data is stored under which database.

As a result, the above 200-instance scenario can be stored using a different database instead of having so many instances open.

How to switch DB in Redis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.