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.

35 lines
611 B

  1. package redisrpc
  2. import (
  3. "git.tetele.net/tgo/conf"
  4. "github.com/golang/protobuf/proto"
  5. )
  6. /**
  7. * 使用用户名查询
  8. */
  9. func HGetString(key, field string, url ...string) (string, error) {
  10. var rpc_url string = "127.0.0.1:" + conf.REDIS_RPC_PORT
  11. if len(url) > 0 && url[0] != "" {
  12. rpc_url = url[0]
  13. }
  14. conn, _, err := DialRedisService("tcp", rpc_url)
  15. if err != nil {
  16. return "", err
  17. }
  18. defer conn.Close()
  19. req := &HGetRequest{proto.String(key), proto.String(field), nil}
  20. res := &GetStringResponse{}
  21. err = conn.HGet(req, res)
  22. if err != nil {
  23. return "", err
  24. }
  25. return res.GetValue(), nil
  26. }