redis rpc服务, 提供redis操作方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

51 lines
763 B

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
}