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.

34 lines
546 B

  1. package redisrpc
  2. import (
  3. "github.com/golang/protobuf/proto"
  4. )
  5. /**
  6. * 使用用户名查询
  7. */
  8. func GetByKey(key string, url ...string) (string, error) {
  9. var user_rpc_url string = "127.0.0.1:7953"
  10. if len(url) > 0 && url[0] != "" {
  11. user_rpc_url = url[0]
  12. }
  13. conn, _, err := DialRedisService("tcp", user_rpc_url)
  14. if err != nil {
  15. return "", err
  16. }
  17. defer conn.Close()
  18. req := &GetKey{proto.String(key), nil}
  19. res := &GetResponse{}
  20. err = conn.GetByKey(req, res)
  21. if err != nil {
  22. return "", err
  23. }
  24. return res.GetString_(), nil
  25. }