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
92c5ab40
Commit
92c5ab40
authored
Dec 02, 2014
by
antirez
Browse files
Use exp format and more precision output for ZSCAN.
Ref: issue #2175
parent
5bd3b9d9
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
92c5ab40
...
@@ -381,7 +381,7 @@ void scanCallback(void *privdata, const dictEntry *de) {
...
@@ -381,7 +381,7 @@ void scanCallback(void *privdata, const dictEntry *de) {
}
else
if
(
o
->
type
==
REDIS_ZSET
)
{
}
else
if
(
o
->
type
==
REDIS_ZSET
)
{
key
=
dictGetKey
(
de
);
key
=
dictGetKey
(
de
);
incrRefCount
(
key
);
incrRefCount
(
key
);
val
=
createStringObjectFromLongDouble
(
*
(
double
*
)
dictGetVal
(
de
));
val
=
createStringObjectFromLongDouble
(
*
(
double
*
)
dictGetVal
(
de
)
,
0
);
}
else
{
}
else
{
redisPanic
(
"Type not handled in SCAN callback."
);
redisPanic
(
"Type not handled in SCAN callback."
);
}
}
...
...
src/object.c
View file @
92c5ab40
...
@@ -109,9 +109,11 @@ robj *createStringObjectFromLongLong(long long value) {
...
@@ -109,9 +109,11 @@ robj *createStringObjectFromLongLong(long long value) {
return
o
;
return
o
;
}
}
/* Note: this function is defined into object.c since here it is where it
/* Create a string object from a long double. If humanfriendly is non-zero
* belongs but it is actually designed to be used just for INCRBYFLOAT */
* it does not use exponential format and trims trailing zeroes at the end,
robj
*
createStringObjectFromLongDouble
(
long
double
value
)
{
* however this result in loss of precision. Otherwise exp format is used
* and the output of snprintf() is not modified. */
robj
*
createStringObjectFromLongDouble
(
long
double
value
,
int
humanfriendly
)
{
char
buf
[
256
];
char
buf
[
256
];
int
len
;
int
len
;
...
@@ -120,15 +122,19 @@ robj *createStringObjectFromLongDouble(long double value) {
...
@@ -120,15 +122,19 @@ robj *createStringObjectFromLongDouble(long double value) {
* that is "non surprising" for the user (that is, most small decimal
* that is "non surprising" for the user (that is, most small decimal
* numbers will be represented in a way that when converted back into
* numbers will be represented in a way that when converted back into
* a string are exactly the same as what the user typed.) */
* a string are exactly the same as what the user typed.) */
len
=
snprintf
(
buf
,
sizeof
(
buf
),
"%.17Lf"
,
value
);
if
(
humanfriendly
)
{
/* Now remove trailing zeroes after the '.' */
len
=
snprintf
(
buf
,
sizeof
(
buf
),
"%.17Lf"
,
value
);
if
(
strchr
(
buf
,
'.'
)
!=
NULL
)
{
/* Now remove trailing zeroes after the '.' */
char
*
p
=
buf
+
len
-
1
;
if
(
strchr
(
buf
,
'.'
)
!=
NULL
)
{
while
(
*
p
==
'0'
)
{
char
*
p
=
buf
+
len
-
1
;
p
--
;
while
(
*
p
==
'0'
)
{
len
--
;
p
--
;
len
--
;
}
if
(
*
p
==
'.'
)
len
--
;
}
}
if
(
*
p
==
'.'
)
len
--
;
}
else
{
len
=
snprintf
(
buf
,
sizeof
(
buf
),
"%.17Lg"
,
value
);
}
}
return
createStringObject
(
buf
,
len
);
return
createStringObject
(
buf
,
len
);
}
}
...
...
src/redis.h
View file @
92c5ab40
...
@@ -1116,7 +1116,7 @@ robj *tryObjectEncoding(robj *o);
...
@@ -1116,7 +1116,7 @@ robj *tryObjectEncoding(robj *o);
robj
*
getDecodedObject
(
robj
*
o
);
robj
*
getDecodedObject
(
robj
*
o
);
size_t
stringObjectLen
(
robj
*
o
);
size_t
stringObjectLen
(
robj
*
o
);
robj
*
createStringObjectFromLongLong
(
long
long
value
);
robj
*
createStringObjectFromLongLong
(
long
long
value
);
robj
*
createStringObjectFromLongDouble
(
long
double
value
);
robj
*
createStringObjectFromLongDouble
(
long
double
value
,
int
humanfriendly
);
robj
*
createListObject
(
void
);
robj
*
createListObject
(
void
);
robj
*
createZiplistObject
(
void
);
robj
*
createZiplistObject
(
void
);
robj
*
createSetObject
(
void
);
robj
*
createSetObject
(
void
);
...
...
src/t_hash.c
View file @
92c5ab40
...
@@ -565,7 +565,7 @@ void hincrbyfloatCommand(redisClient *c) {
...
@@ -565,7 +565,7 @@ void hincrbyfloatCommand(redisClient *c) {
}
}
value
+=
incr
;
value
+=
incr
;
new
=
createStringObjectFromLongDouble
(
value
);
new
=
createStringObjectFromLongDouble
(
value
,
1
);
hashTypeTryObjectEncoding
(
o
,
&
c
->
argv
[
2
],
NULL
);
hashTypeTryObjectEncoding
(
o
,
&
c
->
argv
[
2
],
NULL
);
hashTypeSet
(
o
,
c
->
argv
[
2
],
new
);
hashTypeSet
(
o
,
c
->
argv
[
2
],
new
);
addReplyBulk
(
c
,
new
);
addReplyBulk
(
c
,
new
);
...
...
src/t_string.c
View file @
92c5ab40
...
@@ -397,7 +397,7 @@ void incrbyfloatCommand(redisClient *c) {
...
@@ -397,7 +397,7 @@ void incrbyfloatCommand(redisClient *c) {
addReplyError
(
c
,
"increment would produce NaN or Infinity"
);
addReplyError
(
c
,
"increment would produce NaN or Infinity"
);
return
;
return
;
}
}
new
=
createStringObjectFromLongDouble
(
value
);
new
=
createStringObjectFromLongDouble
(
value
,
1
);
if
(
o
)
if
(
o
)
dbOverwrite
(
c
->
db
,
c
->
argv
[
1
],
new
);
dbOverwrite
(
c
->
db
,
c
->
argv
[
1
],
new
);
else
else
...
...
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