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
e6621d05
Commit
e6621d05
authored
Dec 31, 2010
by
Pieter Noordhuis
Browse files
Add fields for subscribed channel/pattern names
parent
b758e52e
Changes
2
Show whitespace changes
Inline
Side-by-side
async.c
View file @
e6621d05
...
...
@@ -38,6 +38,47 @@
/* Forward declaration of function in hiredis.c */
void
__redisAppendCommand
(
redisContext
*
c
,
char
*
cmd
,
size_t
len
);
/* Functions managing dictionary of callbacks for pub/sub. */
static
unsigned
int
callbackHash
(
const
void
*
key
)
{
return
dictGenHashFunction
((
unsigned
char
*
)
key
,
sdslen
((
char
*
)
key
));
}
static
void
*
callbackValDup
(
void
*
privdata
,
const
void
*
src
)
{
((
void
)
privdata
);
redisCallback
*
dup
=
malloc
(
sizeof
(
*
dup
));
memcpy
(
dup
,
src
,
sizeof
(
*
dup
));
return
dup
;
}
static
int
callbackKeyCompare
(
void
*
privdata
,
const
void
*
key1
,
const
void
*
key2
)
{
int
l1
,
l2
;
((
void
)
privdata
);
l1
=
sdslen
((
sds
)
key1
);
l2
=
sdslen
((
sds
)
key2
);
if
(
l1
!=
l2
)
return
0
;
return
memcmp
(
key1
,
key2
,
l1
)
==
0
;
}
static
void
callbackKeyDestructor
(
void
*
privdata
,
void
*
key
)
{
((
void
)
privdata
);
sdsfree
((
sds
)
key
);
}
static
void
callbackValDestructor
(
void
*
privdata
,
void
*
val
)
{
((
void
)
privdata
);
free
(
val
);
}
static
dictType
callbackDict
=
{
callbackHash
,
NULL
,
callbackValDup
,
callbackKeyCompare
,
callbackKeyDestructor
,
callbackValDestructor
};
static
redisAsyncContext
*
redisAsyncInitialize
(
redisContext
*
c
)
{
redisAsyncContext
*
ac
=
realloc
(
c
,
sizeof
(
redisAsyncContext
));
c
=
&
(
ac
->
c
);
...
...
@@ -63,6 +104,10 @@ static redisAsyncContext *redisAsyncInitialize(redisContext *c) {
ac
->
replies
.
head
=
NULL
;
ac
->
replies
.
tail
=
NULL
;
ac
->
sub
.
invalid
.
head
=
NULL
;
ac
->
sub
.
invalid
.
tail
=
NULL
;
ac
->
sub
.
channels
=
dictCreate
(
&
callbackDict
,
NULL
);
ac
->
sub
.
patterns
=
dictCreate
(
&
callbackDict
,
NULL
);
return
ac
;
}
...
...
async.h
View file @
e6621d05
...
...
@@ -32,6 +32,7 @@
#ifndef __HIREDIS_ASYNC_H
#define __HIREDIS_ASYNC_H
#include "hiredis.h"
#include "dict.h"
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -88,8 +89,15 @@ typedef struct redisAsyncContext {
/* Called when the first write event was received. */
redisConnectCallback
*
onConnect
;
/* Re
ply
callbacks */
/* Re
gular command
callbacks */
redisCallbackList
replies
;
/* Subscription callbacks */
struct
{
redisCallbackList
invalid
;
dict
*
channels
;
dict
*
patterns
;
}
sub
;
}
redisAsyncContext
;
/* Functions that proxy to hiredis */
...
...
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