From e9318d92dbee9421409f6959fc089fa25b90e9a3 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 4 Mar 2013 11:14:32 +0100 Subject: [PATCH] redis-cli: use keepalive socket option. This should improve things in two ways: 1) Prevent timeouts caused by the execution of long commands. 2) Improve detection of real connection errors. This is mostly effective only on Linux because of the bogus default keepalive settings. In Linux we have OS-specific calls to set the keepalive interval to reasonable values. --- src/redis-cli.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/redis-cli.c b/src/redis-cli.c index c182ac17..a7795513 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -56,6 +56,7 @@ #define OUTPUT_STANDARD 0 #define OUTPUT_RAW 1 #define OUTPUT_CSV 2 +#define REDIS_CLI_KEEPALIVE_INTERVAL 15 /* seconds */ static redisContext *context; static struct config { @@ -332,6 +333,12 @@ static int cliConnect(int force) { return REDIS_ERR; } + /* Set aggressive KEEP_ALIVE socket option in the Redis context socket + * in order to prevent timeouts caused by the execution of long + * commands. At the same time this improves the detection of real + * errors. */ + anetKeepAlive(NULL, context->fd, REDIS_CLI_KEEPALIVE_INTERVAL); + /* Do AUTH and select the right DB. */ if (cliAuth() != REDIS_OK) return REDIS_ERR; -- GitLab