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.

76 lines
1.1 KiB

  1. package redisrpc
  2. import (
  3. "github.com/golang/protobuf/proto"
  4. )
  5. //设置
  6. func SAdd(key, field string, url ...string) (int64, error) {
  7. conn, _, err := Conn(url...)
  8. if err != nil {
  9. return 0, err
  10. }
  11. defer conn.Close()
  12. req := &SSetRequest{proto.String(key), proto.String(field), nil}
  13. res := &SSetResponse{}
  14. err = conn.SAdd(req, res)
  15. if err != nil {
  16. return 0, err
  17. }
  18. return res.GetRet(), nil
  19. }
  20. //删除
  21. func SRem(key string, field string, url ...string) (int64, error) {
  22. conn, _, err := Conn(url...)
  23. if err != nil {
  24. return 0, err
  25. }
  26. defer conn.Close()
  27. req := &SSetRequest{proto.String(key), proto.String(field), nil}
  28. res := &SSetResponse{}
  29. err = conn.SRem(req, res)
  30. if err != nil {
  31. return 0, err
  32. }
  33. return res.GetRet(), nil
  34. }
  35. /**
  36. * 全部
  37. */
  38. func SIsmember(key string, field string, url ...string) (int64, error) {
  39. conn, _, err := Conn(url...)
  40. if err != nil {
  41. return 0, err
  42. }
  43. defer conn.Close()
  44. req := &SSetRequest{proto.String(key), proto.String(field), nil}
  45. res := &SSetResponse{}
  46. err = conn.SIsmember(req, res)
  47. if err != nil {
  48. return 0, err
  49. }
  50. return res.GetRet(), nil
  51. }