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
045b1f63
Commit
045b1f63
authored
Dec 06, 2018
by
antirez
Browse files
RESP3: hiredis: save the original double string.
parent
ee4c355a
Changes
4
Hide whitespace changes
Inline
Side-by-side
deps/hiredis/hiredis.c
View file @
045b1f63
...
...
@@ -47,7 +47,7 @@ static redisReply *createReplyObject(int type);
static
void
*
createStringObject
(
const
redisReadTask
*
task
,
char
*
str
,
size_t
len
);
static
void
*
createArrayObject
(
const
redisReadTask
*
task
,
int
elements
);
static
void
*
createIntegerObject
(
const
redisReadTask
*
task
,
long
long
value
);
static
void
*
createDoubleObject
(
const
redisReadTask
*
task
,
double
value
);
static
void
*
createDoubleObject
(
const
redisReadTask
*
task
,
double
value
,
char
*
str
,
size_t
len
);
static
void
*
createNilObject
(
const
redisReadTask
*
task
);
/* Default set of functions to build the reply. Keep in mind that such a
...
...
@@ -95,6 +95,7 @@ void freeReplyObject(void *reply) {
case
REDIS_REPLY_ERROR
:
case
REDIS_REPLY_STATUS
:
case
REDIS_REPLY_STRING
:
case
REDIS_REPLY_DOUBLE
:
free
(
r
->
str
);
break
;
}
...
...
@@ -181,7 +182,7 @@ static void *createIntegerObject(const redisReadTask *task, long long value) {
return
r
;
}
static
void
*
createDoubleObject
(
const
redisReadTask
*
task
,
double
value
)
{
static
void
*
createDoubleObject
(
const
redisReadTask
*
task
,
double
value
,
char
*
str
,
size_t
len
)
{
redisReply
*
r
,
*
parent
;
r
=
createReplyObject
(
REDIS_REPLY_DOUBLE
);
...
...
@@ -189,6 +190,19 @@ static void *createDoubleObject(const redisReadTask *task, double value) {
return
NULL
;
r
->
dval
=
value
;
r
->
str
=
malloc
(
len
+
1
);
if
(
r
->
str
==
NULL
)
{
freeReplyObject
(
r
);
return
NULL
;
}
/* The double reply also has the original protocol string representing a
* double as a null terminated string. This way the caller does not need
* to format back for string conversion, especially since Redis does efforts
* to make the string more human readable avoiding the calssical double
* decimal string conversion artifacts. */
memcpy
(
r
->
str
,
str
,
len
);
r
->
str
[
len
]
=
'\0'
;
if
(
task
->
parent
)
{
parent
=
task
->
parent
->
obj
;
...
...
deps/hiredis/hiredis.h
View file @
045b1f63
...
...
@@ -90,7 +90,8 @@ typedef struct redisReply {
long
long
integer
;
/* The integer when type is REDIS_REPLY_INTEGER */
double
dval
;
/* The double when type is REDIS_REPLY_DOUBLE */
size_t
len
;
/* Length of string */
char
*
str
;
/* Used for both REDIS_REPLY_ERROR and REDIS_REPLY_STRING */
char
*
str
;
/* Used for REDIS_REPLY_ERROR, REDIS_REPLY_STRING
and REDIS_REPLY_DOUBLE (in additionl to dval). */
size_t
elements
;
/* number of elements, for REDIS_REPLY_ARRAY */
struct
redisReply
**
element
;
/* elements vector for REDIS_REPLY_ARRAY */
}
redisReply
;
...
...
deps/hiredis/read.c
View file @
045b1f63
...
...
@@ -304,7 +304,7 @@ static int processLineItem(redisReader *r) {
return
REDIS_ERR
;
}
}
obj
=
r
->
fn
->
createDouble
(
cur
,
d
);
obj
=
r
->
fn
->
createDouble
(
cur
,
d
,
buf
,
len
);
}
else
{
obj
=
(
void
*
)
REDIS_REPLY_DOUBLE
;
}
...
...
deps/hiredis/read.h
View file @
045b1f63
...
...
@@ -81,7 +81,7 @@ typedef struct redisReplyObjectFunctions {
void
*
(
*
createString
)(
const
redisReadTask
*
,
char
*
,
size_t
);
void
*
(
*
createArray
)(
const
redisReadTask
*
,
int
);
void
*
(
*
createInteger
)(
const
redisReadTask
*
,
long
long
);
void
*
(
*
createDouble
)(
const
redisReadTask
*
,
double
);
void
*
(
*
createDouble
)(
const
redisReadTask
*
,
double
,
char
*
,
size_t
);
void
*
(
*
createNil
)(
const
redisReadTask
*
);
void
(
*
freeObject
)(
void
*
);
}
redisReplyObjectFunctions
;
...
...
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