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