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.

649 lines
18 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. SetExpireRequest
  16. GetStringResponse
  17. HGetListResponse
  18. SetResponse
  19. DelResponse
  20. HSetResponse
  21. SetExpireResponse
  22. SSetRequest
  23. SMembersRequest
  24. SSetResponse
  25. LSetRequest
  26. LSetResponse
  27. LRangeRequest
  28. LLenRequest
  29. */
  30. package redisrpc
  31. import proto "github.com/chai2010/protorpc/proto"
  32. import math "math"
  33. import "io"
  34. import "log"
  35. import "net"
  36. import "net/rpc"
  37. import "time"
  38. import protorpc "github.com/chai2010/protorpc"
  39. // Reference imports to suppress errors if they are not otherwise used.
  40. var _ = proto.Marshal
  41. var _ = math.Inf
  42. // 使用key查询
  43. type GetRequest struct {
  44. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  45. XXX_unrecognized []byte `json:"-"`
  46. }
  47. func (m *GetRequest) Reset() { *m = GetRequest{} }
  48. func (m *GetRequest) String() string { return proto.CompactTextString(m) }
  49. func (*GetRequest) ProtoMessage() {}
  50. func (m *GetRequest) GetKey() string {
  51. if m != nil && m.Key != nil {
  52. return *m.Key
  53. }
  54. return ""
  55. }
  56. // 设置key
  57. type SetRequest struct {
  58. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  59. Value *string `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
  60. Ttl *int64 `protobuf:"varint,3,opt,name=ttl" json:"ttl,omitempty"`
  61. XXX_unrecognized []byte `json:"-"`
  62. }
  63. func (m *SetRequest) Reset() { *m = SetRequest{} }
  64. func (m *SetRequest) String() string { return proto.CompactTextString(m) }
  65. func (*SetRequest) ProtoMessage() {}
  66. func (m *SetRequest) GetKey() string {
  67. if m != nil && m.Key != nil {
  68. return *m.Key
  69. }
  70. return ""
  71. }
  72. func (m *SetRequest) GetValue() string {
  73. if m != nil && m.Value != nil {
  74. return *m.Value
  75. }
  76. return ""
  77. }
  78. func (m *SetRequest) GetTtl() int64 {
  79. if m != nil && m.Ttl != nil {
  80. return *m.Ttl
  81. }
  82. return 0
  83. }
  84. type DelRequest struct {
  85. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  86. XXX_unrecognized []byte `json:"-"`
  87. }
  88. func (m *DelRequest) Reset() { *m = DelRequest{} }
  89. func (m *DelRequest) String() string { return proto.CompactTextString(m) }
  90. func (*DelRequest) ProtoMessage() {}
  91. func (m *DelRequest) GetKey() string {
  92. if m != nil && m.Key != nil {
  93. return *m.Key
  94. }
  95. return ""
  96. }
  97. // 使用hash key查询
  98. type HGetRequest struct {
  99. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  100. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  101. XXX_unrecognized []byte `json:"-"`
  102. }
  103. func (m *HGetRequest) Reset() { *m = HGetRequest{} }
  104. func (m *HGetRequest) String() string { return proto.CompactTextString(m) }
  105. func (*HGetRequest) ProtoMessage() {}
  106. func (m *HGetRequest) GetKey() string {
  107. if m != nil && m.Key != nil {
  108. return *m.Key
  109. }
  110. return ""
  111. }
  112. func (m *HGetRequest) GetField() string {
  113. if m != nil && m.Field != nil {
  114. return *m.Field
  115. }
  116. return ""
  117. }
  118. // 设置hash key
  119. type HSetRequest struct {
  120. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  121. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  122. Value *string `protobuf:"bytes,3,opt,name=value" json:"value,omitempty"`
  123. XXX_unrecognized []byte `json:"-"`
  124. }
  125. func (m *HSetRequest) Reset() { *m = HSetRequest{} }
  126. func (m *HSetRequest) String() string { return proto.CompactTextString(m) }
  127. func (*HSetRequest) ProtoMessage() {}
  128. func (m *HSetRequest) GetKey() string {
  129. if m != nil && m.Key != nil {
  130. return *m.Key
  131. }
  132. return ""
  133. }
  134. func (m *HSetRequest) GetField() string {
  135. if m != nil && m.Field != nil {
  136. return *m.Field
  137. }
  138. return ""
  139. }
  140. func (m *HSetRequest) GetValue() string {
  141. if m != nil && m.Value != nil {
  142. return *m.Value
  143. }
  144. return ""
  145. }
  146. // 删除hash key
  147. type HDelRequest struct {
  148. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  149. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  150. XXX_unrecognized []byte `json:"-"`
  151. }
  152. func (m *HDelRequest) Reset() { *m = HDelRequest{} }
  153. func (m *HDelRequest) String() string { return proto.CompactTextString(m) }
  154. func (*HDelRequest) ProtoMessage() {}
  155. func (m *HDelRequest) GetKey() string {
  156. if m != nil && m.Key != nil {
  157. return *m.Key
  158. }
  159. return ""
  160. }
  161. func (m *HDelRequest) GetField() string {
  162. if m != nil && m.Field != nil {
  163. return *m.Field
  164. }
  165. return ""
  166. }
  167. // 有效期
  168. type SetExpireRequest struct {
  169. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  170. Expire *int64 `protobuf:"varint,2,opt,name=expire" json:"expire,omitempty"`
  171. XXX_unrecognized []byte `json:"-"`
  172. }
  173. func (m *SetExpireRequest) Reset() { *m = SetExpireRequest{} }
  174. func (m *SetExpireRequest) String() string { return proto.CompactTextString(m) }
  175. func (*SetExpireRequest) ProtoMessage() {}
  176. func (m *SetExpireRequest) GetKey() string {
  177. if m != nil && m.Key != nil {
  178. return *m.Key
  179. }
  180. return ""
  181. }
  182. func (m *SetExpireRequest) GetExpire() int64 {
  183. if m != nil && m.Expire != nil {
  184. return *m.Expire
  185. }
  186. return 0
  187. }
  188. // 使用key查询响应结构
  189. type GetStringResponse struct {
  190. Value *string `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"`
  191. XXX_unrecognized []byte `json:"-"`
  192. }
  193. func (m *GetStringResponse) Reset() { *m = GetStringResponse{} }
  194. func (m *GetStringResponse) String() string { return proto.CompactTextString(m) }
  195. func (*GetStringResponse) ProtoMessage() {}
  196. func (m *GetStringResponse) GetValue() string {
  197. if m != nil && m.Value != nil {
  198. return *m.Value
  199. }
  200. return ""
  201. }
  202. // 使用key查询响应结构
  203. type HGetListResponse struct {
  204. List []byte `protobuf:"bytes,1,opt,name=list" json:"list,omitempty"`
  205. XXX_unrecognized []byte `json:"-"`
  206. }
  207. func (m *HGetListResponse) Reset() { *m = HGetListResponse{} }
  208. func (m *HGetListResponse) String() string { return proto.CompactTextString(m) }
  209. func (*HGetListResponse) ProtoMessage() {}
  210. func (m *HGetListResponse) GetList() []byte {
  211. if m != nil {
  212. return m.List
  213. }
  214. return nil
  215. }
  216. // 设置key响应结构
  217. type SetResponse struct {
  218. Ret *string `protobuf:"bytes,1,opt,name=ret" json:"ret,omitempty"`
  219. XXX_unrecognized []byte `json:"-"`
  220. }
  221. func (m *SetResponse) Reset() { *m = SetResponse{} }
  222. func (m *SetResponse) String() string { return proto.CompactTextString(m) }
  223. func (*SetResponse) ProtoMessage() {}
  224. func (m *SetResponse) GetRet() string {
  225. if m != nil && m.Ret != nil {
  226. return *m.Ret
  227. }
  228. return ""
  229. }
  230. // 删除key响应结构
  231. type DelResponse struct {
  232. Ret *int64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  233. XXX_unrecognized []byte `json:"-"`
  234. }
  235. func (m *DelResponse) Reset() { *m = DelResponse{} }
  236. func (m *DelResponse) String() string { return proto.CompactTextString(m) }
  237. func (*DelResponse) ProtoMessage() {}
  238. func (m *DelResponse) GetRet() int64 {
  239. if m != nil && m.Ret != nil {
  240. return *m.Ret
  241. }
  242. return 0
  243. }
  244. // 设置key响应结构
  245. type HSetResponse struct {
  246. Ret *int64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  247. XXX_unrecognized []byte `json:"-"`
  248. }
  249. func (m *HSetResponse) Reset() { *m = HSetResponse{} }
  250. func (m *HSetResponse) String() string { return proto.CompactTextString(m) }
  251. func (*HSetResponse) ProtoMessage() {}
  252. func (m *HSetResponse) GetRet() int64 {
  253. if m != nil && m.Ret != nil {
  254. return *m.Ret
  255. }
  256. return 0
  257. }
  258. // 设置key有效期
  259. type SetExpireResponse struct {
  260. Ret *int64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  261. XXX_unrecognized []byte `json:"-"`
  262. }
  263. func (m *SetExpireResponse) Reset() { *m = SetExpireResponse{} }
  264. func (m *SetExpireResponse) String() string { return proto.CompactTextString(m) }
  265. func (*SetExpireResponse) ProtoMessage() {}
  266. func (m *SetExpireResponse) GetRet() int64 {
  267. if m != nil && m.Ret != nil {
  268. return *m.Ret
  269. }
  270. return 0
  271. }
  272. // 集合添加值
  273. type SSetRequest struct {
  274. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  275. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  276. XXX_unrecognized []byte `json:"-"`
  277. }
  278. func (m *SSetRequest) Reset() { *m = SSetRequest{} }
  279. func (m *SSetRequest) String() string { return proto.CompactTextString(m) }
  280. func (*SSetRequest) ProtoMessage() {}
  281. func (m *SSetRequest) GetKey() string {
  282. if m != nil && m.Key != nil {
  283. return *m.Key
  284. }
  285. return ""
  286. }
  287. func (m *SSetRequest) GetField() string {
  288. if m != nil && m.Field != nil {
  289. return *m.Field
  290. }
  291. return ""
  292. }
  293. // 集合添加值
  294. type SMembersRequest struct {
  295. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  296. XXX_unrecognized []byte `json:"-"`
  297. }
  298. func (m *SMembersRequest) Reset() { *m = SMembersRequest{} }
  299. func (m *SMembersRequest) String() string { return proto.CompactTextString(m) }
  300. func (*SMembersRequest) ProtoMessage() {}
  301. func (m *SMembersRequest) GetKey() string {
  302. if m != nil && m.Key != nil {
  303. return *m.Key
  304. }
  305. return ""
  306. }
  307. // 设置响应结构
  308. type SSetResponse struct {
  309. Ret *int64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  310. XXX_unrecognized []byte `json:"-"`
  311. }
  312. func (m *SSetResponse) Reset() { *m = SSetResponse{} }
  313. func (m *SSetResponse) String() string { return proto.CompactTextString(m) }
  314. func (*SSetResponse) ProtoMessage() {}
  315. func (m *SSetResponse) GetRet() int64 {
  316. if m != nil && m.Ret != nil {
  317. return *m.Ret
  318. }
  319. return 0
  320. }
  321. // 列表添加值
  322. type LSetRequest struct {
  323. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  324. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  325. XXX_unrecognized []byte `json:"-"`
  326. }
  327. func (m *LSetRequest) Reset() { *m = LSetRequest{} }
  328. func (m *LSetRequest) String() string { return proto.CompactTextString(m) }
  329. func (*LSetRequest) ProtoMessage() {}
  330. func (m *LSetRequest) GetKey() string {
  331. if m != nil && m.Key != nil {
  332. return *m.Key
  333. }
  334. return ""
  335. }
  336. func (m *LSetRequest) GetField() string {
  337. if m != nil && m.Field != nil {
  338. return *m.Field
  339. }
  340. return ""
  341. }
  342. // 设置key响应结构
  343. type LSetResponse struct {
  344. Ret *int64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  345. XXX_unrecognized []byte `json:"-"`
  346. }
  347. func (m *LSetResponse) Reset() { *m = LSetResponse{} }
  348. func (m *LSetResponse) String() string { return proto.CompactTextString(m) }
  349. func (*LSetResponse) ProtoMessage() {}
  350. func (m *LSetResponse) GetRet() int64 {
  351. if m != nil && m.Ret != nil {
  352. return *m.Ret
  353. }
  354. return 0
  355. }
  356. // 列表取值
  357. type LRangeRequest struct {
  358. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  359. Start *int64 `protobuf:"varint,2,opt,name=start" json:"start,omitempty"`
  360. Stop *int64 `protobuf:"varint,3,opt,name=stop" json:"stop,omitempty"`
  361. XXX_unrecognized []byte `json:"-"`
  362. }
  363. func (m *LRangeRequest) Reset() { *m = LRangeRequest{} }
  364. func (m *LRangeRequest) String() string { return proto.CompactTextString(m) }
  365. func (*LRangeRequest) ProtoMessage() {}
  366. func (m *LRangeRequest) GetKey() string {
  367. if m != nil && m.Key != nil {
  368. return *m.Key
  369. }
  370. return ""
  371. }
  372. func (m *LRangeRequest) GetStart() int64 {
  373. if m != nil && m.Start != nil {
  374. return *m.Start
  375. }
  376. return 0
  377. }
  378. func (m *LRangeRequest) GetStop() int64 {
  379. if m != nil && m.Stop != nil {
  380. return *m.Stop
  381. }
  382. return 0
  383. }
  384. // 列表长度
  385. type LLenRequest struct {
  386. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  387. XXX_unrecognized []byte `json:"-"`
  388. }
  389. func (m *LLenRequest) Reset() { *m = LLenRequest{} }
  390. func (m *LLenRequest) String() string { return proto.CompactTextString(m) }
  391. func (*LLenRequest) ProtoMessage() {}
  392. func (m *LLenRequest) GetKey() string {
  393. if m != nil && m.Key != nil {
  394. return *m.Key
  395. }
  396. return ""
  397. }
  398. func init() {
  399. }
  400. type RedisService interface {
  401. Get(in *GetRequest, out *GetStringResponse) error
  402. Set(in *SetRequest, out *SetResponse) error
  403. Del(in *DelRequest, out *DelResponse) error
  404. HGet(in *HGetRequest, out *GetStringResponse) error
  405. HSet(in *HSetRequest, out *HSetResponse) error
  406. HDel(in *HDelRequest, out *DelResponse) error
  407. SetExpire(in *SetExpireRequest, out *SetExpireResponse) error
  408. HGetAll(in *GetRequest, out *HGetListResponse) error
  409. HGetList(in *GetRequest, out *HGetListResponse) error
  410. HExists(in *HGetRequest, out *DelResponse) error
  411. Exists(in *GetRequest, out *DelResponse) error
  412. HIncrby(in *GetRequest, out *DelResponse) error
  413. SAdd(in *SSetRequest, out *SSetResponse) error
  414. SIsmember(in *SSetRequest, out *SSetResponse) error
  415. SRem(in *SSetRequest, out *SSetResponse) error
  416. LLpush(in *LSetRequest, out *LSetResponse) error
  417. LRpush(in *LSetRequest, out *LSetResponse) error
  418. LRange(in *LRangeRequest, out *HGetListResponse) error
  419. LLen(in *LLenRequest, out *LSetResponse) error
  420. ReduceStock(in *SetRequest, out *SetResponse) error
  421. }
  422. // AcceptRedisServiceClient accepts connections on the listener and serves requests
  423. // for each incoming connection. Accept blocks; the caller typically
  424. // invokes it in a go statement.
  425. func AcceptRedisServiceClient(lis net.Listener, x RedisService) {
  426. srv := rpc.NewServer()
  427. if err := srv.RegisterName("RedisService", x); err != nil {
  428. log.Fatal(err)
  429. }
  430. for {
  431. conn, err := lis.Accept()
  432. if err != nil {
  433. log.Fatalf("lis.Accept(): %v\n", err)
  434. }
  435. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  436. }
  437. }
  438. // RegisterRedisService publish the given RedisService implementation on the server.
  439. func RegisterRedisService(srv *rpc.Server, x RedisService) error {
  440. if err := srv.RegisterName("RedisService", x); err != nil {
  441. return err
  442. }
  443. return nil
  444. }
  445. // NewRedisServiceServer returns a new RedisService Server.
  446. func NewRedisServiceServer(x RedisService) *rpc.Server {
  447. srv := rpc.NewServer()
  448. if err := srv.RegisterName("RedisService", x); err != nil {
  449. log.Fatal(err)
  450. }
  451. return srv
  452. }
  453. // ListenAndServeRedisService listen announces on the local network address laddr
  454. // and serves the given RedisService implementation.
  455. func ListenAndServeRedisService(network, addr string, x RedisService) error {
  456. lis, err := net.Listen(network, addr)
  457. if err != nil {
  458. return err
  459. }
  460. defer lis.Close()
  461. srv := rpc.NewServer()
  462. if err := srv.RegisterName("RedisService", x); err != nil {
  463. return err
  464. }
  465. for {
  466. conn, err := lis.Accept()
  467. if err != nil {
  468. log.Fatalf("lis.Accept(): %v\n", err)
  469. }
  470. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  471. }
  472. }
  473. type RedisServiceClient struct {
  474. *rpc.Client
  475. }
  476. // NewRedisServiceClient returns a RedisService rpc.Client and stub to handle
  477. // requests to the set of RedisService at the other end of the connection.
  478. func NewRedisServiceClient(conn io.ReadWriteCloser) (*RedisServiceClient, *rpc.Client) {
  479. c := rpc.NewClientWithCodec(protorpc.NewClientCodec(conn))
  480. return &RedisServiceClient{c}, c
  481. }
  482. func (c *RedisServiceClient) Get(in *GetRequest, out *GetStringResponse) error {
  483. return c.Call("RedisService.Get", in, out)
  484. }
  485. func (c *RedisServiceClient) Set(in *SetRequest, out *SetResponse) error {
  486. return c.Call("RedisService.Set", in, out)
  487. }
  488. func (c *RedisServiceClient) Del(in *DelRequest, out *DelResponse) error {
  489. return c.Call("RedisService.Del", in, out)
  490. }
  491. func (c *RedisServiceClient) HGet(in *HGetRequest, out *GetStringResponse) error {
  492. return c.Call("RedisService.HGet", in, out)
  493. }
  494. func (c *RedisServiceClient) HSet(in *HSetRequest, out *HSetResponse) error {
  495. return c.Call("RedisService.HSet", in, out)
  496. }
  497. func (c *RedisServiceClient) HDel(in *HDelRequest, out *DelResponse) error {
  498. return c.Call("RedisService.HDel", in, out)
  499. }
  500. func (c *RedisServiceClient) SetExpire(in *SetExpireRequest, out *SetExpireResponse) error {
  501. return c.Call("RedisService.SetExpire", in, out)
  502. }
  503. func (c *RedisServiceClient) HGetAll(in *GetRequest, out *HGetListResponse) error {
  504. return c.Call("RedisService.HGetAll", in, out)
  505. }
  506. func (c *RedisServiceClient) HGetList(in *GetRequest, out *HGetListResponse) error {
  507. return c.Call("RedisService.HGetList", in, out)
  508. }
  509. func (c *RedisServiceClient) HExists(in *HGetRequest, out *DelResponse) error {
  510. return c.Call("RedisService.HExists", in, out)
  511. }
  512. func (c *RedisServiceClient) Exists(in *GetRequest, out *DelResponse) error {
  513. return c.Call("RedisService.Exists", in, out)
  514. }
  515. func (c *RedisServiceClient) HIncrby(in *GetRequest, out *DelResponse) error {
  516. return c.Call("RedisService.HIncrby", in, out)
  517. }
  518. func (c *RedisServiceClient) SAdd(in *SSetRequest, out *SSetResponse) error {
  519. return c.Call("RedisService.SAdd", in, out)
  520. }
  521. func (c *RedisServiceClient) SIsmember(in *SSetRequest, out *SSetResponse) error {
  522. return c.Call("RedisService.SIsmember", in, out)
  523. }
  524. func (c *RedisServiceClient) SRem(in *SSetRequest, out *SSetResponse) error {
  525. return c.Call("RedisService.SRem", in, out)
  526. }
  527. func (c *RedisServiceClient) LLpush(in *LSetRequest, out *LSetResponse) error {
  528. return c.Call("RedisService.LLpush", in, out)
  529. }
  530. func (c *RedisServiceClient) LRpush(in *LSetRequest, out *LSetResponse) error {
  531. return c.Call("RedisService.LRpush", in, out)
  532. }
  533. func (c *RedisServiceClient) LRange(in *LRangeRequest, out *HGetListResponse) error {
  534. return c.Call("RedisService.LRange", in, out)
  535. }
  536. func (c *RedisServiceClient) LLen(in *LLenRequest, out *LSetResponse) error {
  537. return c.Call("RedisService.LLen", in, out)
  538. }
  539. func (c *RedisServiceClient) ReduceStock(in *SetRequest, out *SetResponse) error {
  540. return c.Call("RedisService.ReduceStock", in, out)
  541. }
  542. // DialRedisService connects to an RedisService at the specified network address.
  543. func DialRedisService(network, addr string) (*RedisServiceClient, *rpc.Client, error) {
  544. c, err := protorpc.Dial(network, addr)
  545. if err != nil {
  546. return nil, nil, err
  547. }
  548. return &RedisServiceClient{c}, c, nil
  549. }
  550. // DialRedisServiceTimeout connects to an RedisService at the specified network address.
  551. func DialRedisServiceTimeout(network, addr string,
  552. timeout time.Duration) (*RedisServiceClient, *rpc.Client, error) {
  553. c, err := protorpc.DialTimeout(network, addr, timeout)
  554. if err != nil {
  555. return nil, nil, err
  556. }
  557. return &RedisServiceClient{c}, c, nil
  558. }