[Go]redis Server and client keepalive parameters (tcp-keepalive) settings

Source: Internet
Author: User
Tags redis server

Recently, using the Redis list for cross-process Message Queuing, clients are using Redis-cplusplus-client. This client library is fine, and it's handy to have a consistent interface with redis command line.

The following problem was found during use.

I have multiple clients connecting to the same database, and the client Blpop data from Redis, setting the timeout to 5 seconds. Ordinarily there is no problem, the client is not many, there is no pressure on the database. But after running for a while, the client will not get data from Redis.

The first thing to think about is whether the database connection is broken. View the 6379-port TCP connection from both the Redis and client sides, and find that the connection to the client is not true. But the client was no exception, still in that silly blpop! It seems that this third-party library is still not well done.

One solution is to not maintain a long connection between client and Redis, and each operation is reconnected. feasible, but too simple.

Later, I looked at the Redis configuration file and found a tcp-keepalive option.

# TCP KeepAlive.
#
# If Non-zero, use so_keepalive to send TCP ACKs to clients in absence
# of communication. This was useful for the reasons:
#
# 1) Detect dead peers.
# 2) Take the connection alive from the point of view of the network
# Equipment in the middle.
#
# on Linux, the specified value (in seconds) are the period used to send ACKs.
# Note that to close the connection, the double of the time is needed.
# on and kernels the period depends on the kernel configuration.
#
# A Reasonable value for this option is seconds.
Tcp-keepalive 0

It is used to periodically send tcp_ack packets to the client to detect if the client is alive. Default does not detect, the official recommended value is 60 seconds. Then try it.

This setting, after observing a period of time, discovers that the connection between the client and the Redis is maintained. Work!

For more my articles, visit: 01 Stream (www.it-refer.com)

[Go]redis Server and client keepalive parameters (tcp-keepalive) settings

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.