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.

77 lines
1.1 KiB

  1. package redisrpc
  2. import (
  3. "github.com/golang/protobuf/proto"
  4. )
  5. /**
  6. * 使用用户名查询
  7. */
  8. func HGetString(key, field string, url ...string) (string, error) {
  9. conn, _, err := Conn(url...)
  10. if err != nil {
  11. return "", err
  12. }
  13. defer conn.Close()
  14. req := &HGetRequest{proto.String(key), proto.String(field), nil}
  15. res := &GetStringResponse{}
  16. err = conn.HGet(req, res)
  17. if err != nil {
  18. return "", err
  19. }
  20. return res.GetValue(), nil
  21. }
  22. //设置
  23. func HSet(key, field, value string, url ...string) (uint64, error) {
  24. conn, _, err := Conn(url...)
  25. if err != nil {
  26. return 0, err
  27. }
  28. defer conn.Close()
  29. req := &HSetRequest{proto.String(key), proto.String(field), proto.String(value), nil}
  30. res := &HSetResponse{}
  31. err = conn.HSet(req, res)
  32. if err != nil {
  33. return 0, err
  34. }
  35. return res.GetRet(), nil
  36. }
  37. //删除
  38. func HDel(key string, field string, url ...string) (uint64, error) {
  39. conn, _, err := Conn(url...)
  40. if err != nil {
  41. return 0, err
  42. }
  43. defer conn.Close()
  44. req := &HDelRequest{proto.String(key), proto.String(field), nil}
  45. res := &DelResponse{}
  46. err = conn.HDel(req, res)
  47. if err != nil {
  48. return 0, err
  49. }
  50. return res.GetRet(), nil
  51. }