Skip to content

Commit

Permalink
fix hincrby/hincrbyfloat err info
Browse files Browse the repository at this point in the history
  • Loading branch information
zhs committed Jan 10, 2019
1 parent dbf4d78 commit bed519a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions command/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ var (
// ErrInteger value is not an integer or out of range
ErrInteger = errors.New("ERR value is not an integer or out of range")

// ErrFloat value is not a valid float
ErrFloat = errors.New("ERR value is not a valid float")

// ErrBitInteger bit is not an integer or out of range
ErrBitInteger = errors.New("ERR bit is not an integer or out of range")

Expand Down
4 changes: 2 additions & 2 deletions command/hashes.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func HIncrBy(ctx *Context, txn *db.Transaction) (OnCommit, error) {
field := []byte(ctx.Args[1])
incr, err := strconv.ParseInt(ctx.Args[2], 10, 64)
if err != nil {
return nil, errors.New("ERR " + err.Error())
return nil, ErrInteger
}

hash, err := txn.Hash(key)
Expand All @@ -150,7 +150,7 @@ func HIncrByFloat(ctx *Context, txn *db.Transaction) (OnCommit, error) {
field := []byte(ctx.Args[1])
incr, err := strconv.ParseFloat(ctx.Args[2], 64)
if err != nil {
return nil, errors.New("ERR " + err.Error())
return nil, ErrFloat
}

hash, err := txn.Hash(key)
Expand Down
5 changes: 3 additions & 2 deletions db/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package db
import (
"bytes"
"encoding/binary"
"errors"
"math/rand"
"strconv"

Expand Down Expand Up @@ -423,7 +424,7 @@ func (hash *Hash) HIncrBy(field []byte, v int64) (int64, error) {
} else {
n, err = strconv.ParseInt(string(val), 10, 64)
if err != nil {
return 0, err
return 0, errors.New("hash value is not an integer")
}

}
Expand Down Expand Up @@ -466,7 +467,7 @@ func (hash *Hash) HIncrByFloat(field []byte, v float64) (float64, error) {
} else {
n, err = strconv.ParseFloat(string(val), 64)
if err != nil {
return 0, err
return 0, errors.New("hash value is not an float")
}

}
Expand Down

0 comments on commit bed519a

Please sign in to comment.