diff --git a/hiredis.c b/hiredis.c index 6f60294..ddc6374 100644 --- a/hiredis.c +++ b/hiredis.c @@ -685,7 +685,9 @@ redisContext *redisConnectWithOptions(const redisOptions *options) { return NULL; } if (options->timeout != NULL && (c->flags & REDIS_BLOCK) && c->fd != REDIS_INVALID_FD) { - redisContextSetTimeout(c, *options->timeout); + if (!(options->options & REDIS_OPT_NORDWRTIMEOUT)) { + redisContextSetTimeout(c, *options->timeout); + } } return c; } @@ -703,6 +705,7 @@ redisContext *redisConnectWithTimeout(const char *ip, int port, const struct tim redisOptions options = {0}; REDIS_OPTIONS_SET_TCP(&options, ip, port); options.timeout = &tv; + options.options |= REDIS_OPT_NORDWRTIMEOUT; return redisConnectWithOptions(&options); } diff --git a/hiredis.h b/hiredis.h index 6e56c5e..efd3e64 100644 --- a/hiredis.h +++ b/hiredis.h @@ -133,6 +133,13 @@ struct redisSsl; */ #define REDIS_OPT_NOAUTOFREE 0x04 +/** + * When using connectWithOptions, have the timeout only apply to the + * initial connect, not subsequent read/write attempts. This option + * is here to support the legacy connectWithTimeout() + */ +#define REDIS_OPT_NORDWRTIMEOUT 0x08 + /* In Unix systems a file descriptor is a regular signed int, with -1 * representing an invalid descriptor. In Windows it is a SOCKET * (32- or 64-bit unsigned integer depending on the architecture), where