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
redis
Commits
13966522
Commit
13966522
authored
Nov 21, 2018
by
antirez
Browse files
RESP3: bring RESP2 compatibility to previous changes.
parent
e14aabf9
Changes
2
Show whitespace changes
Inline
Side-by-side
src/networking.c
View file @
13966522
...
...
@@ -473,23 +473,25 @@ void setDeferredArrayLen(client *c, void *node, long length) {
}
void setDeferredMapLen(client *c, void *node, long length) {
setDeferredAggregateLen
(
c
,
node
,
length
,
'%'
);
int prefix = c->resp == 2 ? '*' : '%';
if (c->resp == 2) length *= 2;
setDeferredAggregateLen(c,node,length,prefix);
}
void setDeferredSetLen(client *c, void *node, long length) {
setDeferredAggregateLen
(
c
,
node
,
length
,
'~'
);
int prefix = c->resp == 2 ? '*' : '~';
setDeferredAggregateLen(c,node,length,prefix);
}
void setDeferredAttributeLen(client *c, void *node, long length) {
setDeferredAggregateLen
(
c
,
node
,
length
,
'|'
);
int prefix = c->resp == 2 ? '*' : '|';
if (c->resp == 2) length *= 2;
setDeferredAggregateLen(c,node,length,prefix);
}
void setDeferredPushLen(client *c, void *node, long length) {
setDeferredAggregateLen
(
c
,
node
,
length
,
'>'
);
}
void
setDeferredHelloLen
(
client
*
c
,
void
*
node
,
long
length
)
{
setDeferredAggregateLen
(
c
,
node
,
length
,
'@'
);
int prefix = c->resp == 2 ? '*' : '>';
setDeferredAggregateLen(c,node,length,prefix);
}
/* Add a double as a bulk reply */
...
...
@@ -497,24 +499,42 @@ void addReplyDouble(client *c, double d) {
if (isinf(d)) {
/* Libc in odd systems (Hi Solaris!) will format infinite in a
* different way, so better to handle it in an explicit way. */
if (c->resp == 2) {
addReplyBulkCString(c, d > 0 ? "inf" : "-inf");
} else {
addReplyString(c, d > 0 ? ",inf\r\n" : "-inf\r\n",
d > 0 ? 6 : 7);
}
} else {
char dbuf[MAX_LONG_DOUBLE_CHARS+3],
sbuf[MAX_LONG_DOUBLE_CHARS+32];
int dlen, slen;
if (c->resp == 2) {
dlen = snprintf(dbuf,sizeof(dbuf),"%.17g",d);
slen = snprintf(sbuf,sizeof(sbuf),"$%d\r\n%s\r\n",dlen,dbuf);
addReplyString(c,sbuf,slen);
} else {
char
dbuf
[
MAX_LONG_DOUBLE_CHARS
+
3
];
int
dlen
=
snprintf
(
dbuf
,
sizeof
(
dbuf
),
",%.17g
\r\n
"
,
d
);
dlen = snprintf(dbuf,sizeof(dbuf),",%.17g\r\n",d);
addReplyString(c,dbuf,dlen);
}
}
}
/* Add a long double as a bulk reply, but uses a human readable formatting
* of the double instead of exposing the crude behavior of doubles to the
* dear user. */
void addReplyHumanLongDouble(client *c, long double d) {
if (c->resp == 2) {
robj *o = createStringObjectFromLongDouble(d,1);
addReplyBulk(c,o);
decrRefCount(o);
} else {
char buf[MAX_LONG_DOUBLE_CHARS];
int len = ld2string(buf,sizeof(buf),d,1);
addReplyString(c,",",1);
addReplyString(c,buf,len);
addReplyString(c,"\r\n",2);
}
}
/* Add a long long as integer reply or bulk len / multi bulk count.
...
...
@@ -563,6 +583,7 @@ void addReplyArrayLen(client *c, long length) {
void addReplyMapLen(client *c, long length) {
int prefix = c->resp == 2 ? '*' : '%';
if (c->resp == 2) length *= 2;
addReplyAggregateLen(c,length,prefix);
}
...
...
@@ -573,6 +594,7 @@ void addReplySetLen(client *c, long length) {
void addReplyAttributeLen(client *c, long length) {
int prefix = c->resp == 2 ? '*' : '|';
if (c->resp == 2) length *= 2;
addReplyAggregateLen(c,length,prefix);
}
...
...
src/server.h
View file @
13966522
...
...
@@ -1431,7 +1431,6 @@ void setDeferredMapLen(client *c, void *node, long length);
void
setDeferredSetLen
(
client
*
c
,
void
*
node
,
long
length
);
void
setDeferredAttributeLen
(
client
*
c
,
void
*
node
,
long
length
);
void
setDeferredPushLen
(
client
*
c
,
void
*
node
,
long
length
);
void
setDeferredHelloLen
(
client
*
c
,
void
*
node
,
long
length
);
void
processInputBuffer
(
client
*
c
);
void
processInputBufferAndReplicate
(
client
*
c
);
void
acceptHandler
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
);
...
...
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