From d0e15d4c1de4dfa206bc0bacbdd233e7eee032fb Mon Sep 17 00:00:00 2001 From: silentsai Date: Thu, 5 Jun 2014 11:49:12 +0800 Subject: [PATCH] fix bug - unify the return score type to bluk while call rangeXXX --- ledis/t_zset_test.go | 2 +- server/cmd_zset.go | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ledis/t_zset_test.go b/ledis/t_zset_test.go index 92c0a3d..202da70 100644 --- a/ledis/t_zset_test.go +++ b/ledis/t_zset_test.go @@ -77,7 +77,7 @@ func TestDBZSet(t *testing.T) { t.Fatal(s) } - if s, err := db.ZScore(key, bin("zzz")); err != errScoreMiss || s != InvalidScore { + if s, err := db.ZScore(key, bin("zzz")); err != ErrScoreMiss || s != InvalidScore { t.Fatal(fmt.Sprintf("s=[%d] err=[%s]", s, err)) } diff --git a/server/cmd_zset.go b/server/cmd_zset.go index d9cb78a..c72fa71 100644 --- a/server/cmd_zset.go +++ b/server/cmd_zset.go @@ -110,7 +110,7 @@ func zincrbyCommand(c *client) error { if v, err := c.db.ZIncrBy(key, delta, args[2]); err != nil { return err } else { - c.writeBulk(v) + c.writeBulk(ledis.StrPutInt64(v)) } return nil @@ -312,10 +312,16 @@ func zrangeGeneric(c *client, reverse bool) error { withScores = true } - if v, err := c.db.ZRangeGeneric(key, start, stop, withScores, reverse); err != nil { + if datas, err := c.db.ZRangeGeneric(key, start, stop, withScores, reverse); err != nil { return err } else { - c.writeArray(v) + if withScores { + for i := len(datas) - 1; i > 0; i -= 2 { + v, _ := datas[i].(int64) + datas[i] = ledis.StrPutInt64(v) + } + } + c.writeArray(datas) } return nil } @@ -377,10 +383,16 @@ func zrangebyscoreGeneric(c *client, reverse bool) error { return nil } - if v, err := c.db.ZRangeByScoreGeneric(key, min, max, withScores, offset, count, reverse); err != nil { + if datas, err := c.db.ZRangeByScoreGeneric(key, min, max, withScores, offset, count, reverse); err != nil { return err } else { - c.writeArray(v) + if withScores { + for i := len(datas) - 1; i > 0; i -= 2 { + v, _ := datas[i].(int64) + datas[i] = ledis.StrPutInt64(v) + } + } + c.writeArray(datas) } return nil