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
7b705936
Commit
7b705936
authored
Dec 06, 2018
by
Mark Nunberg
Browse files
libevent-example: Use timeout
parent
53d9b12b
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/example-libevent.c
View file @
7b705936
...
@@ -9,7 +9,12 @@
...
@@ -9,7 +9,12 @@
void
getCallback
(
redisAsyncContext
*
c
,
void
*
r
,
void
*
privdata
)
{
void
getCallback
(
redisAsyncContext
*
c
,
void
*
r
,
void
*
privdata
)
{
redisReply
*
reply
=
r
;
redisReply
*
reply
=
r
;
if
(
reply
==
NULL
)
return
;
if
(
reply
==
NULL
)
{
if
(
c
->
errstr
)
{
printf
(
"errstr: %s
\n
"
,
c
->
errstr
);
}
return
;
}
printf
(
"argv[%s]: %s
\n
"
,
(
char
*
)
privdata
,
reply
->
str
);
printf
(
"argv[%s]: %s
\n
"
,
(
char
*
)
privdata
,
reply
->
str
);
/* Disconnect after receiving the reply to GET */
/* Disconnect after receiving the reply to GET */
...
@@ -35,8 +40,14 @@ void disconnectCallback(const redisAsyncContext *c, int status) {
...
@@ -35,8 +40,14 @@ void disconnectCallback(const redisAsyncContext *c, int status) {
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
signal
(
SIGPIPE
,
SIG_IGN
);
signal
(
SIGPIPE
,
SIG_IGN
);
struct
event_base
*
base
=
event_base_new
();
struct
event_base
*
base
=
event_base_new
();
redisOptions
options
=
{
0
};
REDIS_OPTIONS_SET_TCP
(
&
options
,
"127.0.0.1"
,
6379
);
struct
timeval
tv
=
{
0
};
tv
.
tv_sec
=
1
;
options
.
timeout
=
&
tv
;
redisAsyncContext
*
c
=
redisAsyncConnect
(
"127.0.0.1"
,
6379
);
redisAsyncContext
*
c
=
redisAsyncConnect
WithOptions
(
&
options
);
if
(
c
->
err
)
{
if
(
c
->
err
)
{
/* Let *c leak for now... */
/* Let *c leak for now... */
printf
(
"Error: %s
\n
"
,
c
->
errstr
);
printf
(
"Error: %s
\n
"
,
c
->
errstr
);
...
...
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