don't automatically use timeout for read/write timeout with...

connectWithTimeout()

The timeout value will still be used for I/O if using
connectWithOptions()
This commit is contained in:
Mark Nunberg 2019-04-15 07:51:11 -04:00
parent 5aa2397f9e
commit f12d52c1ed
2 changed files with 11 additions and 1 deletions

View File

@ -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);
}

View File

@ -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