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
9e417047
Commit
9e417047
authored
Sep 25, 2010
by
Pieter Noordhuis
Browse files
Add function to free an allocated context
parent
cab99f64
Changes
3
Hide whitespace changes
Inline
Side-by-side
hiredis.c
View file @
9e417047
...
...
@@ -586,6 +586,17 @@ static redisContext *redisContextInit(redisReplyFunctions *fn) {
return
c
;
}
void
redisFree
(
redisContext
*
c
)
{
if
(
c
->
error
!=
NULL
)
sdsfree
(
c
->
error
);
if
(
c
->
obuf
!=
NULL
)
sdsfree
(
c
->
obuf
);
if
(
c
->
clen
>
0
)
free
(
c
->
callbacks
);
redisReplyReaderFree
(
c
->
reader
);
free
(
c
);
}
/* Connect to a Redis instance. On error the field error in the returned
* context will be set to the return value of the error function.
* When no set of reply functions is given, the default set will be used. */
...
...
hiredis.h
View file @
9e417047
...
...
@@ -103,6 +103,7 @@ 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
redisFree
(
redisContext
*
c
);
int
redisBufferRead
(
redisContext
*
c
);
int
redisBufferWrite
(
redisContext
*
c
,
int
*
done
);
int
redisGetReply
(
redisContext
*
c
,
void
**
reply
);
...
...
test.c
View file @
9e417047
...
...
@@ -28,16 +28,17 @@ int main(void) {
int
i
,
ret
,
tests
=
0
,
fails
=
0
;
long
long
t1
,
t2
;
redisContext
*
c
;
redisReply
*
reply
;
redisReply
*
reply
,
**
replies
;
void
*
reader
;
char
*
err
;
__connect
(
&
c
);
__connect
(
&
c
);
test
(
"Returns I/O error when the connection is lost: "
);
test_cond
(
redisCommand
(
c
,
"QUIT"
)
==
NULL
&&
strcmp
(
c
->
error
,
"Server closed the connection"
)
==
0
);
__connect
(
&
c
);
/* reconnect */
redisFree
(
c
);
__connect
(
&
c
);
/* reconnect */
test
(
"Is able to deliver commands: "
);
reply
=
redisCommand
(
c
,
"PING"
);
test_cond
(
reply
->
type
==
REDIS_REPLY_STRING
&&
...
...
@@ -170,5 +171,6 @@ int main(void) {
printf
(
"*** %d TESTS FAILED ***
\n
"
,
fails
);
}
redisFree
(
c
);
return
0
;
}
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