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
83bba659
"vscode:/vscode.git/clone" did not exist on "7140894f2f7f6d96f772f912459ede0740a728c5"
Unverified
Commit
83bba659
authored
May 21, 2020
by
Michael Grunder
Committed by
GitHub
May 21, 2020
Browse files
Add logic to handle RESP3 push messages (#819)
Fixes #815
parent
c8999c66
Changes
4
Hide whitespace changes
Inline
Side-by-side
async.c
View file @
83bba659
...
...
@@ -374,7 +374,7 @@ static int __redisGetSubscribeCallback(redisAsyncContext *ac, redisReply *reply,
/* Custom reply functions are not supported for pub/sub. This will fail
* very hard when they are used... */
if
(
reply
->
type
==
REDIS_REPLY_ARRAY
)
{
if
(
reply
->
type
==
REDIS_REPLY_ARRAY
||
reply
->
type
==
REDIS_REPLY_PUSH
)
{
assert
(
reply
->
elements
>=
2
);
assert
(
reply
->
element
[
0
]
->
type
==
REDIS_REPLY_STRING
);
stype
=
reply
->
element
[
0
]
->
str
;
...
...
hiredis.c
View file @
83bba659
...
...
@@ -97,6 +97,7 @@ void freeReplyObject(void *reply) {
case
REDIS_REPLY_ARRAY
:
case
REDIS_REPLY_MAP
:
case
REDIS_REPLY_SET
:
case
REDIS_REPLY_PUSH
:
if
(
r
->
element
!=
NULL
)
{
for
(
j
=
0
;
j
<
r
->
elements
;
j
++
)
freeReplyObject
(
r
->
element
[
j
]);
...
...
@@ -155,7 +156,8 @@ static void *createStringObject(const redisReadTask *task, char *str, size_t len
parent
=
task
->
parent
->
obj
;
assert
(
parent
->
type
==
REDIS_REPLY_ARRAY
||
parent
->
type
==
REDIS_REPLY_MAP
||
parent
->
type
==
REDIS_REPLY_SET
);
parent
->
type
==
REDIS_REPLY_SET
||
parent
->
type
==
REDIS_REPLY_PUSH
);
parent
->
element
[
task
->
idx
]
=
r
;
}
return
r
;
...
...
@@ -201,7 +203,8 @@ static void *createIntegerObject(const redisReadTask *task, long long value) {
parent
=
task
->
parent
->
obj
;
assert
(
parent
->
type
==
REDIS_REPLY_ARRAY
||
parent
->
type
==
REDIS_REPLY_MAP
||
parent
->
type
==
REDIS_REPLY_SET
);
parent
->
type
==
REDIS_REPLY_SET
||
parent
->
type
==
REDIS_REPLY_PUSH
);
parent
->
element
[
task
->
idx
]
=
r
;
}
return
r
;
...
...
read.c
View file @
83bba659
...
...
@@ -250,7 +250,8 @@ static void moveToNextTask(redisReader *r) {
prv
=
r
->
task
[
r
->
ridx
-
1
];
assert
(
prv
->
type
==
REDIS_REPLY_ARRAY
||
prv
->
type
==
REDIS_REPLY_MAP
||
prv
->
type
==
REDIS_REPLY_SET
);
prv
->
type
==
REDIS_REPLY_SET
||
prv
->
type
==
REDIS_REPLY_PUSH
);
if
(
cur
->
idx
==
prv
->
elements
-
1
)
{
r
->
ridx
--
;
}
else
{
...
...
@@ -562,6 +563,9 @@ static int processItem(redisReader *r) {
case
'='
:
cur
->
type
=
REDIS_REPLY_VERB
;
break
;
case
'>'
:
cur
->
type
=
REDIS_REPLY_PUSH
;
break
;
default:
__redisReaderSetErrorProtocolByte
(
r
,
*
p
);
return
REDIS_ERR
;
...
...
@@ -587,6 +591,7 @@ static int processItem(redisReader *r) {
case
REDIS_REPLY_ARRAY
:
case
REDIS_REPLY_MAP
:
case
REDIS_REPLY_SET
:
case
REDIS_REPLY_PUSH
:
return
processAggregateItem
(
r
);
default:
assert
(
NULL
);
...
...
test.c
View file @
83bba659
...
...
@@ -488,6 +488,21 @@ static void test_reply_reader(void) {
!
memcmp
(((
redisReply
*
)
reply
)
->
str
,
"LOLWUT"
,
6
));
freeReplyObject
(
reply
);
redisReaderFree
(
reader
);
/* RESP3 push messages (Github issue #815) */
test
(
"Can parse RESP3 push messages: "
);
reader
=
redisReaderCreate
();
redisReaderFeed
(
reader
,(
char
*
)
">2
\r\n
$6
\r\n
LOLWUT
\r\n
:42
\r\n
"
,
21
);
ret
=
redisReaderGetReply
(
reader
,
&
reply
);
test_cond
(
ret
==
REDIS_OK
&&
((
redisReply
*
)
reply
)
->
type
==
REDIS_REPLY_PUSH
&&
((
redisReply
*
)
reply
)
->
elements
==
2
&&
((
redisReply
*
)
reply
)
->
element
[
0
]
->
type
==
REDIS_REPLY_STRING
&&
!
memcmp
(((
redisReply
*
)
reply
)
->
element
[
0
]
->
str
,
"LOLWUT"
,
6
)
&&
((
redisReply
*
)
reply
)
->
element
[
1
]
->
type
==
REDIS_REPLY_INTEGER
&&
((
redisReply
*
)
reply
)
->
element
[
1
]
->
integer
==
42
);
freeReplyObject
(
reply
);
redisReaderFree
(
reader
);
}
static
void
test_free_null
(
void
)
{
...
...
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