Make KeepAlive optional
Make Connection KeepAlive being optional instead of default.
This commit is contained in:
parent
8d5bc445e5
commit
9dff5105fc
@ -1092,6 +1092,13 @@ int redisSetTimeout(redisContext *c, struct timeval tv) {
|
|||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Enable connection KeepAlive. */
|
||||||
|
int redisEnableKeepAlive(redisContext *c) {
|
||||||
|
if (redisKeepAlive(c, REDIS_KEEPALIVE_INTERVAL) != REDIS_OK)
|
||||||
|
return REDIS_ERR;
|
||||||
|
return REDIS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* Use this function to handle a read event on the descriptor. It will try
|
/* Use this function to handle a read event on the descriptor. It will try
|
||||||
* and read some bytes from the socket and feed them to the reply parser.
|
* and read some bytes from the socket and feed them to the reply parser.
|
||||||
*
|
*
|
||||||
|
@ -179,6 +179,7 @@ redisContext *redisConnectUnix(const char *path);
|
|||||||
redisContext *redisConnectUnixWithTimeout(const char *path, struct timeval tv);
|
redisContext *redisConnectUnixWithTimeout(const char *path, struct timeval tv);
|
||||||
redisContext *redisConnectUnixNonBlock(const char *path);
|
redisContext *redisConnectUnixNonBlock(const char *path);
|
||||||
int redisSetTimeout(redisContext *c, struct timeval tv);
|
int redisSetTimeout(redisContext *c, struct timeval tv);
|
||||||
|
int redisEnableKeepAlive(redisContext *c);
|
||||||
void redisFree(redisContext *c);
|
void redisFree(redisContext *c);
|
||||||
int redisBufferRead(redisContext *c);
|
int redisBufferRead(redisContext *c);
|
||||||
int redisBufferWrite(redisContext *c, int *done);
|
int redisBufferWrite(redisContext *c, int *done);
|
||||||
|
7
net.c
7
net.c
@ -113,8 +113,9 @@ static int redisSetBlocking(redisContext *c, int fd, int blocking) {
|
|||||||
return REDIS_OK;
|
return REDIS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int redisKeepAlive(redisContext *c,int fd,int interval) {
|
int redisKeepAlive(redisContext *c, int interval) {
|
||||||
int val = 1;
|
int val = 1;
|
||||||
|
int fd = c->fd;
|
||||||
|
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) == -1){
|
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) == -1){
|
||||||
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
|
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
|
||||||
@ -143,8 +144,6 @@ static int redisKeepAlive(redisContext *c,int fd,int interval) {
|
|||||||
return REDIS_OK;
|
return REDIS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int redisSetTcpNoDelay(redisContext *c, int fd) {
|
static int redisSetTcpNoDelay(redisContext *c, int fd) {
|
||||||
int yes = 1;
|
int yes = 1;
|
||||||
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)) == -1) {
|
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)) == -1) {
|
||||||
@ -273,8 +272,6 @@ int redisContextConnectTcp(redisContext *c, const char *addr, int port, struct t
|
|||||||
goto error;
|
goto error;
|
||||||
if (redisSetTcpNoDelay(c,s) != REDIS_OK)
|
if (redisSetTcpNoDelay(c,s) != REDIS_OK)
|
||||||
goto error;
|
goto error;
|
||||||
if (redisKeepAlive(c,s,REDIS_KEEPALIVE_INTERVAL) != REDIS_OK)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
c->fd = s;
|
c->fd = s;
|
||||||
c->flags |= REDIS_CONNECTED;
|
c->flags |= REDIS_CONNECTED;
|
||||||
|
1
net.h
1
net.h
@ -43,5 +43,6 @@ int redisCheckSocketError(redisContext *c, int fd);
|
|||||||
int redisContextSetTimeout(redisContext *c, struct timeval tv);
|
int redisContextSetTimeout(redisContext *c, struct timeval tv);
|
||||||
int redisContextConnectTcp(redisContext *c, const char *addr, int port, struct timeval *timeout);
|
int redisContextConnectTcp(redisContext *c, const char *addr, int port, struct timeval *timeout);
|
||||||
int redisContextConnectUnix(redisContext *c, const char *path, struct timeval *timeout);
|
int redisContextConnectUnix(redisContext *c, const char *path, struct timeval *timeout);
|
||||||
|
int redisKeepAlive(redisContext *c, int interval);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user