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

3 years ago
  1. package redisrpc
  2. import (
  3. "github.com/golang/protobuf/proto"
  4. )
  5. //加
  6. func Incrby(key string, value int64, url ...string) (int64, error) {
  7. conn, _, err := Conn(url...)
  8. if err != nil {
  9. return 0, err
  10. }
  11. defer conn.Close()
  12. req := &AddRequest{proto.String(key), proto.Int64(value), nil}
  13. res := &AddResponse{}
  14. err = conn.Incrby(req, res)
  15. if err != nil {
  16. return 0, err
  17. }
  18. return res.GetRet(), nil
  19. }
  20. //减
  21. func Decrby(key string, value int64, url ...string) (int64, error) {
  22. conn, _, err := Conn(url...)
  23. if err != nil {
  24. return 0, err
  25. }
  26. defer conn.Close()
  27. req := &AddRequest{proto.String(key), proto.Int64(value), nil}
  28. res := &AddResponse{}
  29. err = conn.Decrby(req, res)
  30. if err != nil {
  31. return 0, err
  32. }
  33. return res.GetRet(), nil
  34. }