fix the type of return value from zscore command

This commit is contained in:
silentsai 2014-06-05 10:20:50 +08:00
parent 4a5f105449
commit dee78beef1
3 changed files with 8 additions and 4 deletions

View File

@ -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")
)

View File

@ -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

View File

@ -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 {
c.writeInteger(s)
return err
}
} else {
c.writeBulk(ledis.StrPutInt64(s))
}
return nil