Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
9cd3b03d
Commit
9cd3b03d
authored
Oct 07, 2010
by
Pieter Noordhuis
Browse files
Fire callback when the context is being disconnected by the user
parent
e5dd32d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
hiredis.c
View file @
9cd3b03d
...
...
@@ -586,6 +586,13 @@ static redisContext *redisContextInit(redisReplyFunctions *fn) {
return
c
;
}
void
redisDisconnect
(
redisContext
*
c
)
{
if
(
c
->
cbDisconnect
!=
NULL
)
c
->
cbDisconnect
(
c
,
c
->
privdataDisconnect
);
close
(
c
->
fd
);
c
->
flags
&=
~
REDIS_CONNECTED
;
}
void
redisFree
(
redisContext
*
c
)
{
if
(
c
->
cbFree
!=
NULL
)
c
->
cbFree
(
c
,
c
->
privdataFree
);
...
...
@@ -605,6 +612,7 @@ void redisFree(redisContext *c) {
redisContext
*
redisConnect
(
const
char
*
ip
,
int
port
,
redisReplyFunctions
*
fn
)
{
redisContext
*
c
=
redisContextInit
(
fn
);
c
->
flags
|=
REDIS_BLOCK
;
c
->
flags
|=
REDIS_CONNECTED
;
redisContextConnect
(
c
,
ip
,
port
);
return
c
;
}
...
...
@@ -612,10 +620,17 @@ redisContext *redisConnect(const char *ip, int port, redisReplyFunctions *fn) {
redisContext
*
redisConnectNonBlock
(
const
char
*
ip
,
int
port
,
redisReplyFunctions
*
fn
)
{
redisContext
*
c
=
redisContextInit
(
fn
);
c
->
flags
&=
~
REDIS_BLOCK
;
c
->
flags
|=
REDIS_CONNECTED
;
redisContextConnect
(
c
,
ip
,
port
);
return
c
;
}
/* Register callback that is triggered when redisDisconnect is called. */
void
redisSetDisconnectCallback
(
redisContext
*
c
,
redisContextCallback
*
fn
,
void
*
privdata
)
{
c
->
cbDisconnect
=
fn
;
c
->
privdataDisconnect
=
privdata
;
}
/* Register callback that is triggered when a command is put in the output
* buffer when the context is non-blocking. */
void
redisSetCommandCallback
(
redisContext
*
c
,
redisContextCallback
*
fn
,
void
*
privdata
)
{
...
...
hiredis.h
View file @
9cd3b03d
...
...
@@ -37,6 +37,10 @@
* least significant bit of the flags field in redisContext. */
#define REDIS_BLOCK 0x1
/* Connection may be disconnected before being free'd. The second bit
* in the flags field is set when the context is connected. */
#define REDIS_CONNECTED 0x2
#define REDIS_ERROR -1
#define REDIS_REPLY_ERROR 0
#define REDIS_REPLY_STRING 1
...
...
@@ -94,6 +98,8 @@ typedef struct redisContext {
void
*
reader
;
/* Non-reply callbacks */
redisContextCallback
*
cbDisconnect
;
void
*
privdataDisconnect
;
redisContextCallback
*
cbCommand
;
void
*
privdataCommand
;
redisContextCallback
*
cbFree
;
...
...
@@ -115,8 +121,10 @@ int redisReplyReaderGetReply(void *reader, void **reply);
redisContext
*
redisConnect
(
const
char
*
ip
,
int
port
,
redisReplyFunctions
*
fn
);
redisContext
*
redisConnectNonBlock
(
const
char
*
ip
,
int
port
,
redisReplyFunctions
*
fn
);
void
redisSetDisconnectCallback
(
redisContext
*
c
,
redisContextCallback
*
fn
,
void
*
privdata
);
void
redisSetCommandCallback
(
redisContext
*
c
,
redisContextCallback
*
fn
,
void
*
privdata
);
void
redisSetFreeCallback
(
redisContext
*
c
,
redisContextCallback
*
fn
,
void
*
privdata
);
void
redisDisconnect
(
redisContext
*
c
);
void
redisFree
(
redisContext
*
c
);
int
redisBufferRead
(
redisContext
*
c
);
int
redisBufferWrite
(
redisContext
*
c
,
int
*
done
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment