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.

192 lines
5.0 KiB

  1. // Code generated by protoc-gen-go.
  2. // source: redis.proto
  3. // DO NOT EDIT!
  4. /*
  5. Package redisrpc is a generated protocol buffer package.
  6. It is generated from these files:
  7. redis.proto
  8. It has these top-level messages:
  9. GetKey
  10. GetHashKey
  11. GetResponse
  12. */
  13. package redisrpc
  14. import proto "github.com/chai2010/protorpc/proto"
  15. import math "math"
  16. import "io"
  17. import "log"
  18. import "net"
  19. import "net/rpc"
  20. import "time"
  21. import protorpc "github.com/chai2010/protorpc"
  22. // Reference imports to suppress errors if they are not otherwise used.
  23. var _ = proto.Marshal
  24. var _ = math.Inf
  25. // 使用key查询
  26. type GetKey struct {
  27. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  28. XXX_unrecognized []byte `json:"-"`
  29. }
  30. func (m *GetKey) Reset() { *m = GetKey{} }
  31. func (m *GetKey) String() string { return proto.CompactTextString(m) }
  32. func (*GetKey) ProtoMessage() {}
  33. func (m *GetKey) GetKey() string {
  34. if m != nil && m.Key != nil {
  35. return *m.Key
  36. }
  37. return ""
  38. }
  39. // 使用hash key查询
  40. type GetHashKey struct {
  41. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  42. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  43. XXX_unrecognized []byte `json:"-"`
  44. }
  45. func (m *GetHashKey) Reset() { *m = GetHashKey{} }
  46. func (m *GetHashKey) String() string { return proto.CompactTextString(m) }
  47. func (*GetHashKey) ProtoMessage() {}
  48. func (m *GetHashKey) GetKey() string {
  49. if m != nil && m.Key != nil {
  50. return *m.Key
  51. }
  52. return ""
  53. }
  54. func (m *GetHashKey) GetField() string {
  55. if m != nil && m.Field != nil {
  56. return *m.Field
  57. }
  58. return ""
  59. }
  60. // 使用key查询响应结构
  61. type GetResponse struct {
  62. String_ *string `protobuf:"bytes,1,opt,name=string" json:"string,omitempty"`
  63. XXX_unrecognized []byte `json:"-"`
  64. }
  65. func (m *GetResponse) Reset() { *m = GetResponse{} }
  66. func (m *GetResponse) String() string { return proto.CompactTextString(m) }
  67. func (*GetResponse) ProtoMessage() {}
  68. func (m *GetResponse) GetString_() string {
  69. if m != nil && m.String_ != nil {
  70. return *m.String_
  71. }
  72. return ""
  73. }
  74. func init() {
  75. }
  76. type RedisService interface {
  77. GetByKey(in *GetKey, out *GetResponse) error
  78. GetByHashKey(in *GetHashKey, out *GetResponse) error
  79. }
  80. // AcceptRedisServiceClient accepts connections on the listener and serves requests
  81. // for each incoming connection. Accept blocks; the caller typically
  82. // invokes it in a go statement.
  83. func AcceptRedisServiceClient(lis net.Listener, x RedisService) {
  84. srv := rpc.NewServer()
  85. if err := srv.RegisterName("RedisService", x); err != nil {
  86. log.Fatal(err)
  87. }
  88. for {
  89. conn, err := lis.Accept()
  90. if err != nil {
  91. log.Fatalf("lis.Accept(): %v\n", err)
  92. }
  93. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  94. }
  95. }
  96. // RegisterRedisService publish the given RedisService implementation on the server.
  97. func RegisterRedisService(srv *rpc.Server, x RedisService) error {
  98. if err := srv.RegisterName("RedisService", x); err != nil {
  99. return err
  100. }
  101. return nil
  102. }
  103. // NewRedisServiceServer returns a new RedisService Server.
  104. func NewRedisServiceServer(x RedisService) *rpc.Server {
  105. srv := rpc.NewServer()
  106. if err := srv.RegisterName("RedisService", x); err != nil {
  107. log.Fatal(err)
  108. }
  109. return srv
  110. }
  111. // ListenAndServeRedisService listen announces on the local network address laddr
  112. // and serves the given RedisService implementation.
  113. func ListenAndServeRedisService(network, addr string, x RedisService) error {
  114. lis, err := net.Listen(network, addr)
  115. if err != nil {
  116. return err
  117. }
  118. defer lis.Close()
  119. srv := rpc.NewServer()
  120. if err := srv.RegisterName("RedisService", x); err != nil {
  121. return err
  122. }
  123. for {
  124. conn, err := lis.Accept()
  125. if err != nil {
  126. log.Fatalf("lis.Accept(): %v\n", err)
  127. }
  128. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  129. }
  130. }
  131. type RedisServiceClient struct {
  132. *rpc.Client
  133. }
  134. // NewRedisServiceClient returns a RedisService rpc.Client and stub to handle
  135. // requests to the set of RedisService at the other end of the connection.
  136. func NewRedisServiceClient(conn io.ReadWriteCloser) (*RedisServiceClient, *rpc.Client) {
  137. c := rpc.NewClientWithCodec(protorpc.NewClientCodec(conn))
  138. return &RedisServiceClient{c}, c
  139. }
  140. func (c *RedisServiceClient) GetByKey(in *GetKey, out *GetResponse) error {
  141. return c.Call("RedisService.GetByKey", in, out)
  142. }
  143. func (c *RedisServiceClient) GetByHashKey(in *GetHashKey, out *GetResponse) error {
  144. return c.Call("RedisService.GetByHashKey", in, out)
  145. }
  146. // DialRedisService connects to an RedisService at the specified network address.
  147. func DialRedisService(network, addr string) (*RedisServiceClient, *rpc.Client, error) {
  148. c, err := protorpc.Dial(network, addr)
  149. if err != nil {
  150. return nil, nil, err
  151. }
  152. return &RedisServiceClient{c}, c, nil
  153. }
  154. // DialRedisServiceTimeout connects to an RedisService at the specified network address.
  155. func DialRedisServiceTimeout(network, addr string,
  156. timeout time.Duration) (*RedisServiceClient, *rpc.Client, error) {
  157. c, err := protorpc.DialTimeout(network, addr, timeout)
  158. if err != nil {
  159. return nil, nil, err
  160. }
  161. return &RedisServiceClient{c}, c, nil
  162. }