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.

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