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

3 years ago
3 years ago
3 years ago
  1. package redisrpc
  2. import (
  3. "github.com/golang/protobuf/proto"
  4. )
  5. /**
  6. * 使用用户名查询
  7. */
  8. func GetString(key string, url ...string) (string, error) {
  9. conn, _, err := Conn(url...)
  10. if err != nil {
  11. return "", err
  12. }
  13. defer conn.Close()
  14. req := &GetRequest{proto.String(key), nil}
  15. res := &GetStringResponse{}
  16. err = conn.Get(req, res)
  17. if err != nil {
  18. return "", err
  19. }
  20. return res.GetValue(), nil
  21. }
  22. //设置
  23. func Set(key, value string, ttl int64, url ...string) (string, error) {
  24. conn, _, err := Conn(url...)
  25. if err != nil {
  26. return "", err
  27. }
  28. defer conn.Close()
  29. req := &SetRequest{proto.String(key), proto.String(value), proto.Int64(ttl), nil}
  30. res := &SetResponse{}
  31. err = conn.Set(req, res)
  32. if err != nil {
  33. return "", err
  34. }
  35. return res.GetRet(), nil
  36. }
  37. //删除
  38. func Del(key 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 := &DelRequest{proto.String(key), nil}
  45. res := &DelResponse{}
  46. err = conn.Del(req, res)
  47. if err != nil {
  48. return 0, err
  49. }
  50. return res.GetRet(), nil
  51. }