|
|
@ -0,0 +1,51 @@ |
|
|
|
package redisrpc |
|
|
|
|
|
|
|
import ( |
|
|
|
"github.com/golang/protobuf/proto" |
|
|
|
) |
|
|
|
|
|
|
|
//加
|
|
|
|
func Incrby(key string, value int64, url ...string) (int64, error) { |
|
|
|
|
|
|
|
conn, _, err := Conn(url...) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
req := &AddRequest{proto.String(key), proto.Int64(value), nil} |
|
|
|
|
|
|
|
res := &AddResponse{} |
|
|
|
|
|
|
|
err = conn.Incrby(req, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
return res.GetRet(), nil |
|
|
|
} |
|
|
|
|
|
|
|
//减
|
|
|
|
func Decrby(key string, value int64, url ...string) (int64, error) { |
|
|
|
|
|
|
|
conn, _, err := Conn(url...) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
req := &AddRequest{proto.String(key), proto.Int64(value), nil} |
|
|
|
|
|
|
|
res := &AddResponse{} |
|
|
|
|
|
|
|
err = conn.Decrby(req, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
return res.GetRet(), nil |
|
|
|
} |