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
914ee431
Commit
914ee431
authored
Nov 07, 2018
by
antirez
Browse files
RESP3: Double replies and aggregate lengths initial functions.
parent
51129857
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/networking.c
View file @
914ee431
...
@@ -469,16 +469,15 @@ void setDeferredMultiBulkLength(client *c, void *node, long length) {
...
@@ -469,16 +469,15 @@ void setDeferredMultiBulkLength(client *c, void *node, long length) {
/* Add a double as a bulk reply */
/* Add a double as a bulk reply */
void addReplyDouble(client *c, double d) {
void addReplyDouble(client *c, double d) {
char dbuf[128], sbuf[128];
int dlen, slen;
if (isinf(d)) {
if (isinf(d)) {
/* Libc in odd systems (Hi Solaris!) will format infinite in a
/* Libc in odd systems (Hi Solaris!) will format infinite in a
* different way, so better to handle it in an explicit way. */
* different way, so better to handle it in an explicit way. */
addReplyBulkCString(c, d > 0 ? "inf" : "-inf");
addReplyString(c, d > 0 ? ",inf\r\n" : "-inf\r\n",
d > 0 ? 6 : 7);
} else {
} else {
dlen = snprintf(dbuf,sizeof(dbuf),"%.17g",d)
;
char dbuf[MAX_LONG_DOUBLE_CHARS+3]
;
s
len = snprintf(
s
buf,sizeof(
s
buf),"
$%d\r\n%s\r\n",dlen,dbuf
);
int d
len = snprintf(
d
buf,sizeof(
d
buf),"
,%.17g\r\n",d
);
addReplyString(c,
s
buf,
s
len);
addReplyString(c,
d
buf,
d
len);
}
}
}
}
...
@@ -486,9 +485,11 @@ void addReplyDouble(client *c, double d) {
...
@@ -486,9 +485,11 @@ void addReplyDouble(client *c, double d) {
* of the double instead of exposing the crude behavior of doubles to the
* of the double instead of exposing the crude behavior of doubles to the
* dear user. */
* dear user. */
void addReplyHumanLongDouble(client *c, long double d) {
void addReplyHumanLongDouble(client *c, long double d) {
robj *o = createStringObjectFromLongDouble(d,1);
char buf[MAX_LONG_DOUBLE_CHARS];
addReplyBulk(c,o);
int len = ld2string(buf,sizeof(buf),d,1);
decrRefCount(o);
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.
/* Add a long long as integer reply or bulk len / multi bulk count.
...
@@ -524,11 +525,35 @@ void addReplyLongLong(client *c, long long ll) {
...
@@ -524,11 +525,35 @@ void addReplyLongLong(client *c, long long ll) {
addReplyLongLongWithPrefix(c,ll,':');
addReplyLongLongWithPrefix(c,ll,':');
}
}
void addReply
MultiBulk
Len(client *c, long length) {
void addReply
Aggregate
Len(client *c, long length
, int prefix
) {
if (length < OBJ_SHARED_BULKHDR_LEN)
if (
prefix == '*' &&
length < OBJ_SHARED_BULKHDR_LEN)
addReply(c,shared.mbulkhdr[length]);
addReply(c,shared.mbulkhdr[length]);
else
else
addReplyLongLongWithPrefix(c,length,'*');
addReplyLongLongWithPrefix(c,length,prefix);
}
void addReplyArrayLen(client *c, long length) {
addReplyAggregateLen(c,length,'*');
}
void addReplyMapLen(client *c, long length) {
addReplyAggregateLen(c,length,'%');
}
void addReplySetLen(client *c, long length) {
addReplyAggregateLen(c,length,'~');
}
void addReplyAttributeLen(client *c, long length) {
addReplyAggregateLen(c,length,'|');
}
void addReplyPushLen(client *c, long length) {
addReplyAggregateLen(c,length,'>');
}
void addReplyHelloLen(client *c, long length) {
addReplyAggregateLen(c,length,'@');
}
}
/* Create the length prefix of a bulk reply, example: $2234 */
/* Create the length prefix of a bulk reply, example: $2234 */
...
...
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