diff --git a/ledis/const.go b/ledis/const.go index 9e4d0cf..ba0cf05 100644 --- a/ledis/const.go +++ b/ledis/const.go @@ -37,4 +37,5 @@ var ( ErrKeySize = errors.New("invalid key size") ErrHashFieldSize = errors.New("invalid hash field size") ErrZSetMemberSize = errors.New("invalid zset member size") + ErrScoreMiss = errors.New("zset score miss") ) diff --git a/ledis/t_zset.go b/ledis/t_zset.go index 372368e..8be54b7 100644 --- a/ledis/t_zset.go +++ b/ledis/t_zset.go @@ -22,7 +22,6 @@ var errZSizeKey = errors.New("invalid zsize key") var errZSetKey = errors.New("invalid zset key") var errZScoreKey = errors.New("invalid zscore key") var errScoreOverflow = errors.New("zset score overflow") -var errScoreMiss = errors.New("zset score miss") const ( zsetNScoreSep byte = '<' @@ -324,7 +323,7 @@ func (db *DB) ZScore(key []byte, member []byte) (int64, error) { if v, err := db.db.Get(k); err != nil { return InvalidScore, err } else if v == nil { - return InvalidScore, errScoreMiss + return InvalidScore, ErrScoreMiss } else { if score, err = Int64(v, nil); err != nil { return InvalidScore, err diff --git a/server/cmd_zset.go b/server/cmd_zset.go index c68f71b..d9cb78a 100644 --- a/server/cmd_zset.go +++ b/server/cmd_zset.go @@ -67,9 +67,13 @@ func zscoreCommand(c *client) error { } if s, err := c.db.ZScore(args[0], args[1]); err != nil { - return err + if err == ledis.ErrScoreMiss { + c.writeBulk(nil) + } else { + return err + } } else { - c.writeInteger(s) + c.writeBulk(ledis.StrPutInt64(s)) } return nil