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.

373 lines
9.8 KiB

3 years ago
3 years ago
3 years ago
  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. GetRequest
  10. SetRequest
  11. DelRequest
  12. HGetRequest
  13. HSetRequest
  14. HDelRequest
  15. GetStringResponse
  16. SetResponse
  17. DelResponse
  18. HSetResponse
  19. */
  20. package redisrpc
  21. import proto "github.com/chai2010/protorpc/proto"
  22. import math "math"
  23. import "io"
  24. import "log"
  25. import "net"
  26. import "net/rpc"
  27. import "time"
  28. import protorpc "github.com/chai2010/protorpc"
  29. // Reference imports to suppress errors if they are not otherwise used.
  30. var _ = proto.Marshal
  31. var _ = math.Inf
  32. // 使用key查询
  33. type GetRequest struct {
  34. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  35. XXX_unrecognized []byte `json:"-"`
  36. }
  37. func (m *GetRequest) Reset() { *m = GetRequest{} }
  38. func (m *GetRequest) String() string { return proto.CompactTextString(m) }
  39. func (*GetRequest) ProtoMessage() {}
  40. func (m *GetRequest) GetKey() string {
  41. if m != nil && m.Key != nil {
  42. return *m.Key
  43. }
  44. return ""
  45. }
  46. // 设置key
  47. type SetRequest struct {
  48. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  49. Value *string `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
  50. Ttl *string `protobuf:"bytes,3,opt,name=ttl" json:"ttl,omitempty"`
  51. XXX_unrecognized []byte `json:"-"`
  52. }
  53. func (m *SetRequest) Reset() { *m = SetRequest{} }
  54. func (m *SetRequest) String() string { return proto.CompactTextString(m) }
  55. func (*SetRequest) ProtoMessage() {}
  56. func (m *SetRequest) GetKey() string {
  57. if m != nil && m.Key != nil {
  58. return *m.Key
  59. }
  60. return ""
  61. }
  62. func (m *SetRequest) GetValue() string {
  63. if m != nil && m.Value != nil {
  64. return *m.Value
  65. }
  66. return ""
  67. }
  68. func (m *SetRequest) GetTtl() string {
  69. if m != nil && m.Ttl != nil {
  70. return *m.Ttl
  71. }
  72. return ""
  73. }
  74. type DelRequest struct {
  75. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  76. XXX_unrecognized []byte `json:"-"`
  77. }
  78. func (m *DelRequest) Reset() { *m = DelRequest{} }
  79. func (m *DelRequest) String() string { return proto.CompactTextString(m) }
  80. func (*DelRequest) ProtoMessage() {}
  81. func (m *DelRequest) GetKey() string {
  82. if m != nil && m.Key != nil {
  83. return *m.Key
  84. }
  85. return ""
  86. }
  87. // 使用hash key查询
  88. type HGetRequest struct {
  89. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  90. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  91. XXX_unrecognized []byte `json:"-"`
  92. }
  93. func (m *HGetRequest) Reset() { *m = HGetRequest{} }
  94. func (m *HGetRequest) String() string { return proto.CompactTextString(m) }
  95. func (*HGetRequest) ProtoMessage() {}
  96. func (m *HGetRequest) GetKey() string {
  97. if m != nil && m.Key != nil {
  98. return *m.Key
  99. }
  100. return ""
  101. }
  102. func (m *HGetRequest) GetField() string {
  103. if m != nil && m.Field != nil {
  104. return *m.Field
  105. }
  106. return ""
  107. }
  108. // 设置hash key
  109. type HSetRequest struct {
  110. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  111. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  112. Value *string `protobuf:"bytes,3,opt,name=value" json:"value,omitempty"`
  113. XXX_unrecognized []byte `json:"-"`
  114. }
  115. func (m *HSetRequest) Reset() { *m = HSetRequest{} }
  116. func (m *HSetRequest) String() string { return proto.CompactTextString(m) }
  117. func (*HSetRequest) ProtoMessage() {}
  118. func (m *HSetRequest) GetKey() string {
  119. if m != nil && m.Key != nil {
  120. return *m.Key
  121. }
  122. return ""
  123. }
  124. func (m *HSetRequest) GetField() string {
  125. if m != nil && m.Field != nil {
  126. return *m.Field
  127. }
  128. return ""
  129. }
  130. func (m *HSetRequest) GetValue() string {
  131. if m != nil && m.Value != nil {
  132. return *m.Value
  133. }
  134. return ""
  135. }
  136. // 删除hash key
  137. type HDelRequest struct {
  138. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  139. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  140. XXX_unrecognized []byte `json:"-"`
  141. }
  142. func (m *HDelRequest) Reset() { *m = HDelRequest{} }
  143. func (m *HDelRequest) String() string { return proto.CompactTextString(m) }
  144. func (*HDelRequest) ProtoMessage() {}
  145. func (m *HDelRequest) GetKey() string {
  146. if m != nil && m.Key != nil {
  147. return *m.Key
  148. }
  149. return ""
  150. }
  151. func (m *HDelRequest) GetField() string {
  152. if m != nil && m.Field != nil {
  153. return *m.Field
  154. }
  155. return ""
  156. }
  157. // 使用key查询响应结构
  158. type GetStringResponse struct {
  159. Value *string `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"`
  160. XXX_unrecognized []byte `json:"-"`
  161. }
  162. func (m *GetStringResponse) Reset() { *m = GetStringResponse{} }
  163. func (m *GetStringResponse) String() string { return proto.CompactTextString(m) }
  164. func (*GetStringResponse) ProtoMessage() {}
  165. func (m *GetStringResponse) GetValue() string {
  166. if m != nil && m.Value != nil {
  167. return *m.Value
  168. }
  169. return ""
  170. }
  171. // 设置key响应结构
  172. type SetResponse struct {
  173. Ret *string `protobuf:"bytes,1,opt,name=ret" json:"ret,omitempty"`
  174. XXX_unrecognized []byte `json:"-"`
  175. }
  176. func (m *SetResponse) Reset() { *m = SetResponse{} }
  177. func (m *SetResponse) String() string { return proto.CompactTextString(m) }
  178. func (*SetResponse) ProtoMessage() {}
  179. func (m *SetResponse) GetRet() string {
  180. if m != nil && m.Ret != nil {
  181. return *m.Ret
  182. }
  183. return ""
  184. }
  185. // 删除key响应结构
  186. type DelResponse struct {
  187. Ret *uint64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  188. XXX_unrecognized []byte `json:"-"`
  189. }
  190. func (m *DelResponse) Reset() { *m = DelResponse{} }
  191. func (m *DelResponse) String() string { return proto.CompactTextString(m) }
  192. func (*DelResponse) ProtoMessage() {}
  193. func (m *DelResponse) GetRet() uint64 {
  194. if m != nil && m.Ret != nil {
  195. return *m.Ret
  196. }
  197. return 0
  198. }
  199. // 设置key响应结构
  200. type HSetResponse struct {
  201. Ret *uint64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  202. XXX_unrecognized []byte `json:"-"`
  203. }
  204. func (m *HSetResponse) Reset() { *m = HSetResponse{} }
  205. func (m *HSetResponse) String() string { return proto.CompactTextString(m) }
  206. func (*HSetResponse) ProtoMessage() {}
  207. func (m *HSetResponse) GetRet() uint64 {
  208. if m != nil && m.Ret != nil {
  209. return *m.Ret
  210. }
  211. return 0
  212. }
  213. func init() {
  214. }
  215. type RedisService interface {
  216. Get(in *GetRequest, out *GetStringResponse) error
  217. Set(in *SetRequest, out *SetResponse) error
  218. Del(in *DelRequest, out *DelResponse) error
  219. HGet(in *HGetRequest, out *GetStringResponse) error
  220. HSet(in *HSetRequest, out *SetResponse) error
  221. HDel(in *HDelRequest, out *DelResponse) error
  222. }
  223. // AcceptRedisServiceClient accepts connections on the listener and serves requests
  224. // for each incoming connection. Accept blocks; the caller typically
  225. // invokes it in a go statement.
  226. func AcceptRedisServiceClient(lis net.Listener, x RedisService) {
  227. srv := rpc.NewServer()
  228. if err := srv.RegisterName("RedisService", x); err != nil {
  229. log.Fatal(err)
  230. }
  231. for {
  232. conn, err := lis.Accept()
  233. if err != nil {
  234. log.Fatalf("lis.Accept(): %v\n", err)
  235. }
  236. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  237. }
  238. }
  239. // RegisterRedisService publish the given RedisService implementation on the server.
  240. func RegisterRedisService(srv *rpc.Server, x RedisService) error {
  241. if err := srv.RegisterName("RedisService", x); err != nil {
  242. return err
  243. }
  244. return nil
  245. }
  246. // NewRedisServiceServer returns a new RedisService Server.
  247. func NewRedisServiceServer(x RedisService) *rpc.Server {
  248. srv := rpc.NewServer()
  249. if err := srv.RegisterName("RedisService", x); err != nil {
  250. log.Fatal(err)
  251. }
  252. return srv
  253. }
  254. // ListenAndServeRedisService listen announces on the local network address laddr
  255. // and serves the given RedisService implementation.
  256. func ListenAndServeRedisService(network, addr string, x RedisService) error {
  257. lis, err := net.Listen(network, addr)
  258. if err != nil {
  259. return err
  260. }
  261. defer lis.Close()
  262. srv := rpc.NewServer()
  263. if err := srv.RegisterName("RedisService", x); err != nil {
  264. return err
  265. }
  266. for {
  267. conn, err := lis.Accept()
  268. if err != nil {
  269. log.Fatalf("lis.Accept(): %v\n", err)
  270. }
  271. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  272. }
  273. }
  274. type RedisServiceClient struct {
  275. *rpc.Client
  276. }
  277. // NewRedisServiceClient returns a RedisService rpc.Client and stub to handle
  278. // requests to the set of RedisService at the other end of the connection.
  279. func NewRedisServiceClient(conn io.ReadWriteCloser) (*RedisServiceClient, *rpc.Client) {
  280. c := rpc.NewClientWithCodec(protorpc.NewClientCodec(conn))
  281. return &RedisServiceClient{c}, c
  282. }
  283. func (c *RedisServiceClient) Get(in *GetRequest, out *GetStringResponse) error {
  284. return c.Call("RedisService.Get", in, out)
  285. }
  286. func (c *RedisServiceClient) Set(in *SetRequest, out *SetResponse) error {
  287. return c.Call("RedisService.Set", in, out)
  288. }
  289. func (c *RedisServiceClient) Del(in *DelRequest, out *DelResponse) error {
  290. return c.Call("RedisService.Del", in, out)
  291. }
  292. func (c *RedisServiceClient) HGet(in *HGetRequest, out *GetStringResponse) error {
  293. return c.Call("RedisService.HGet", in, out)
  294. }
  295. func (c *RedisServiceClient) HSet(in *HSetRequest, out *SetResponse) error {
  296. return c.Call("RedisService.HSet", in, out)
  297. }
  298. func (c *RedisServiceClient) HDel(in *HDelRequest, out *DelResponse) error {
  299. return c.Call("RedisService.HDel", in, out)
  300. }
  301. // DialRedisService connects to an RedisService at the specified network address.
  302. func DialRedisService(network, addr string) (*RedisServiceClient, *rpc.Client, error) {
  303. c, err := protorpc.Dial(network, addr)
  304. if err != nil {
  305. return nil, nil, err
  306. }
  307. return &RedisServiceClient{c}, c, nil
  308. }
  309. // DialRedisServiceTimeout connects to an RedisService at the specified network address.
  310. func DialRedisServiceTimeout(network, addr string,
  311. timeout time.Duration) (*RedisServiceClient, *rpc.Client, error) {
  312. c, err := protorpc.DialTimeout(network, addr, timeout)
  313. if err != nil {
  314. return nil, nil, err
  315. }
  316. return &RedisServiceClient{c}, c, nil
  317. }