Node uses redis to cache data. Do you need to create a link every time a request is made?

  node.js, question

Objective: redis is used to cache the fixed content data of the website when node is opened

Problems encountered:

var redis = require('redis'),
 client = redis.createClient();
 
 client.hset([hash, hashtest, value],function(err,reply){
 callback(err,reply);
 // client.quit();
 });
 
 client.hget([hash,hashtest],function(err,reply){
 callback(err,reply);
 // client.quit();
 })

Does client.quit need to close the link every time the request is completed, and then create the client link again at the time of the request? ?

There are two configurations related to this in the configuration file:
Maxclients is used to set the maximum supported client connection, which is rejected if exceeded. This sets how many connections your redis client can support at the same time; (Of course, in addition to this value, you also need to look at the limit setting of linux system.)
Timeout timeout setting is used to set how long after a user connection has not triggered a redis request, the connection is actively closed from the server side to save system resources;

# Set the max number of connected clients at the same time. By default
 # this limit is set to 10000 clients, however if the Redis server is not
 # able to configure the process file limit to allow for the specified limit
 # the max number of allowed clients is set to the current file limit
 # minus 32 (as Redis reserves a few file descriptors for internal uses).
 #
 # Once the limit is reached Redis will close all the new connections sending
 # an error 'max number of clients reached'.
 #
 # maxclients 10000
 
 # Set the max number of connected clients at the same time. By default
 # this limit is set to 10000 clients, however if the Redis server is not
 # able to configure the process file limit to allow for the specified limit
 # the max number of allowed clients is set to the current file limit
 # minus 32 (as Redis reserves a few file descriptors for internal uses).
 #
 # Once the limit is reached Redis will close all the new connections sending
 # an error 'max number of clients reached'.
 #
 # maxclients 10000
 # Close the connection after a client is idle for N seconds (0 to disable)
 timeout 0

For redis connection requests, there are generally the following two scenario settings:

  1. The number of server triggering user requests is limited (for example, within 100), which can set timeout to 0, so that the redis connection request is always valid and will not be disconnected after one connection. Reconnect only after service restart or error;

  2. A large number of users request concurrently. In this case, timeout can be set within a few minutes (determined according to the business), while the client does not actively close the connection after connecting, and requests the connection after finding that the connection is closed (closed by the server due to timeout);