Q: When and when multiple Redis connections are closed

Source: Internet
Author: User
Shortly after I first came into contact with redis, I had read some information on the Internet, but I still haven't figured it out in many places. now I have two questions. I hope you can help me solve them. 1. Questions about Redis multi-connection. (1) multi-connection refers to the connection established between different projects and Redis? The same item... I just got in touch with redis. I have read some information on the Internet, but I still haven't figured it out in many places. now I have two questions. I hope you can help me solve them.

1. Questions about Redis multi-connection.
(1) multi-connection refers to the connection established between different projects and Redis? You can also establish multiple connections with Redis in the same project.
Connected?
(2) you need to save user and device information in a project. So there is no need to establish two connections, one is used to save user information, the other is used to save device information, or just to establish a connection? Which method is better? Now I only create one connection to store all the data.

2. apsaradb for Redis should be properly shut down.
Scenario: The Server establishes a persistent Socket connection with the Client. the Server receives data from the Client, stores the data in Redis, and stores the data in MySQL.
Problem:
(1) The problem arises. I re-open the data stored in Redis every time and close it after the operation. You can still keep the connection on the machine for a long time. you don't have to close the connection. you can only close the connection when the program is abnormal or exits? I personally think the connection should always be maintained, because frequent IO is required, so frequent connections and shutdown are not suitable.
(2) When should we close the Redis connection?

Reply content:

Shortly after I first came into contact with redis, I had read some information on the Internet, but I still haven't figured it out in many places. now I have two questions. I hope you can help me solve them.

1. Questions about Redis multi-connection.
(1) multi-connection refers to the connection established between different projects and Redis? You can also establish multiple connections with Redis in the same project.
Connected?
(2) you need to save user and device information in a project. So there is no need to establish two connections, one is used to save user information, the other is used to save device information, or just to establish a connection? Which method is better? Now I only create one connection to store all the data.

2. apsaradb for Redis should be properly shut down.
Scenario: The Server establishes a persistent Socket connection with the Client. the Server receives data from the Client, stores the data in Redis, and stores the data in MySQL.
Problem:
(1) The problem arises. I re-open the data stored in Redis every time and close it after the operation. You can still keep the connection on the machine for a long time. you don't have to close the connection. you can only close the connection when the program is abnormal or exits? I personally think the connection should always be maintained, because frequent IO is required, so frequent connections and shutdown are not suitable.
(2) When should we close the Redis connection?

I think you still have a label for PHP. I don't know if you are using Redis in PHP. if so, I don't think the above issues should be your consideration, redis extension should help you set the best solution.

Solve your problems one by one:

  1. Multi-link is not the two situations you mentioned, but refers to a project that establishes multiple links with a Redis instance. the server should be mostly processed concurrently, if you open only one link, multiple requests will be queued up to wait for the link, so currently there will be a multi-link (connection pool) design.

  2. Do not bind each link to actual requirements. In addition, the vast majority of Redis databases are designed to implement connection pools. the links you use are invisible to you, you don't have to worry about the bottom-layer driver.

  3. As you said, the best way is to keep the link, that is, the persistent link, and the block driver has already been written for you. by default, the persistent link is used, therefore, you do not need to deal with the problem of when to close the connection.

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.