Allow option for async connections to not automatically free
This commit is contained in:
parent
1ec4aefba6
commit
5eb6958870
7
async.c
7
async.c
@ -361,7 +361,9 @@ static void __redisAsyncDisconnect(redisAsyncContext *ac) {
|
|||||||
|
|
||||||
/* For non-clean disconnects, __redisAsyncFree() will execute pending
|
/* For non-clean disconnects, __redisAsyncFree() will execute pending
|
||||||
* callbacks with a NULL-reply. */
|
* callbacks with a NULL-reply. */
|
||||||
__redisAsyncFree(ac);
|
if (!(c->flags & REDIS_NO_AUTO_FREE)) {
|
||||||
|
__redisAsyncFree(ac);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tries to do a clean disconnect from Redis, meaning it stops new commands
|
/* Tries to do a clean disconnect from Redis, meaning it stops new commands
|
||||||
@ -373,6 +375,9 @@ static void __redisAsyncDisconnect(redisAsyncContext *ac) {
|
|||||||
void redisAsyncDisconnect(redisAsyncContext *ac) {
|
void redisAsyncDisconnect(redisAsyncContext *ac) {
|
||||||
redisContext *c = &(ac->c);
|
redisContext *c = &(ac->c);
|
||||||
c->flags |= REDIS_DISCONNECTING;
|
c->flags |= REDIS_DISCONNECTING;
|
||||||
|
|
||||||
|
/** unset the auto-free flag here, because disconnect undoes this */
|
||||||
|
c->flags &= ~REDIS_NO_AUTO_FREE;
|
||||||
if (!(c->flags & REDIS_IN_CALLBACK) && ac->replies.head == NULL)
|
if (!(c->flags & REDIS_IN_CALLBACK) && ac->replies.head == NULL)
|
||||||
__redisAsyncDisconnect(ac);
|
__redisAsyncDisconnect(ac);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -668,6 +668,9 @@ redisContext *redisConnectWithOptions(const redisOptions *options) {
|
|||||||
if (options->options & REDIS_OPT_REUSEADDR) {
|
if (options->options & REDIS_OPT_REUSEADDR) {
|
||||||
c->flags |= REDIS_REUSEADDR;
|
c->flags |= REDIS_REUSEADDR;
|
||||||
}
|
}
|
||||||
|
if (options->options & REDIS_OPT_NOAUTOFREE) {
|
||||||
|
c->flags |= REDIS_NO_AUTO_FREE;
|
||||||
|
}
|
||||||
|
|
||||||
if (options->type == REDIS_CONN_TCP) {
|
if (options->type == REDIS_CONN_TCP) {
|
||||||
redisContextConnectBindTcp(c, options->endpoint.tcp.ip,
|
redisContextConnectBindTcp(c, options->endpoint.tcp.ip,
|
||||||
|
|||||||
12
hiredis.h
12
hiredis.h
@ -77,6 +77,12 @@
|
|||||||
/* Flag that is set when this connection is done through SSL */
|
/* Flag that is set when this connection is done through SSL */
|
||||||
#define REDIS_SSL 0x100
|
#define REDIS_SSL 0x100
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag that indicates the user does not want the context to
|
||||||
|
* be automatically freed upon error
|
||||||
|
*/
|
||||||
|
#define REDIS_NO_AUTO_FREE 0x200
|
||||||
|
|
||||||
#define REDIS_KEEPALIVE_INTERVAL 15 /* seconds */
|
#define REDIS_KEEPALIVE_INTERVAL 15 /* seconds */
|
||||||
|
|
||||||
/* number of times we retry to connect in the case of EADDRNOTAVAIL and
|
/* number of times we retry to connect in the case of EADDRNOTAVAIL and
|
||||||
@ -121,6 +127,12 @@ struct redisSsl;
|
|||||||
#define REDIS_OPT_NONBLOCK 0x01
|
#define REDIS_OPT_NONBLOCK 0x01
|
||||||
#define REDIS_OPT_REUSEADDR 0x02
|
#define REDIS_OPT_REUSEADDR 0x02
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Don't automatically free the async object on a connection failure,
|
||||||
|
* or other implicit conditions. Only free on an explicit call to disconnect() or free()
|
||||||
|
*/
|
||||||
|
#define REDIS_OPT_NOAUTOFREE 0x04
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/*
|
/*
|
||||||
* the type of connection to use. This also indicates which
|
* the type of connection to use. This also indicates which
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user