Skip to content

Commit

Permalink
ZSets double to string serialization fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Nov 3, 2009
1 parent 9155ea9 commit eaa256a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
00-RELEASENOTES
*.o
*.rdb
*.log
redis-cli
redis-server
redis-benchmark
doc-tools
mkrelease.sh
release
myredis.conf
misc/*
4 changes: 2 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ VERSION 1.1 TODO
* Add all the missing symbols for the static functions into the table. Crete a Tcl script to check this. This backtrace on segfault is indeed *very* useful.
* Use strcoll() to compare objects in sorted sets, like it already happens for SORT.
* LMOVE, as discussed in the Redis group.
* EXPIRE and EXPIREAT tests.
* Write docs for the "STORE" operaiton of SORT.
* EXPIRE, EXPIREAT, ZSCORE tests.
* Write docs for the "STORE" operaiton of SORT, and GET "#" option.
* Append only mode: testing and a command to rebuild the log from scratch.

VERSION 1.2 TODO
Expand Down
4 changes: 2 additions & 2 deletions redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,7 @@ static int rdbSaveDoubleValue(FILE *fp, double val) {
len = 1;
buf[0] = (val < 0) ? 255 : 254;
} else {
snprintf((char*)buf+1,sizeof(buf)-1,"%.16g",val);
snprintf((char*)buf+1,sizeof(buf)-1,"%.17g",val);
buf[0] = strlen((char*)buf);
len = buf[0]+1;
}
Expand Down Expand Up @@ -4307,7 +4307,7 @@ static void zscoreCommand(redisClient *c) {
char buf[128];
double *score = dictGetEntryVal(de);

snprintf(buf,sizeof(buf),"%.16g",*score);
snprintf(buf,sizeof(buf),"%.17g",*score);
addReplySds(c,sdscatprintf(sdsempty(),"$%d\r\n%s\r\n",
strlen(buf),buf));
}
Expand Down
17 changes: 15 additions & 2 deletions test-redis.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,21 @@ proc main {server port} {
} {{x y z} {y x z}}

test {ZSCORE} {
list [$r zscore ztmp x] [$r zscore ztmp y] [$r zscore ztmp z]
} {10 1 30}
set aux {}
set err {}
for {set i 0} {$i < 1000} {incr i} {
set score [expr rand()]
lappend aux $score
$r zadd zscoretest $score $i
}
for {set i 0} {$i < 1000} {incr i} {
if {[$r zscore zscoretest $i] != [lindex $aux $i]} {
set err "Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i"
break
}
}
set _ $err
} {}

test {ZRANGE and ZREVRANGE} {
list [$r zrange ztmp 0 -1] [$r zrevrange ztmp 0 -1]
Expand Down

0 comments on commit eaa256a

Please sign in to comment.