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.

421 lines
11 KiB

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