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.

653 lines
18 KiB

3 years ago
3 years ago
3 years ago
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. SetNx(in *SetRequest, out *DelResponse) error
  404. Del(in *DelRequest, out *DelResponse) error
  405. HGet(in *HGetRequest, out *GetStringResponse) error
  406. HSet(in *HSetRequest, out *HSetResponse) error
  407. HDel(in *HDelRequest, out *DelResponse) error
  408. SetExpire(in *SetExpireRequest, out *SetExpireResponse) error
  409. HGetAll(in *GetRequest, out *HGetListResponse) error
  410. HGetList(in *GetRequest, out *HGetListResponse) error
  411. HExists(in *HGetRequest, out *DelResponse) error
  412. Exists(in *GetRequest, out *DelResponse) error
  413. HIncrby(in *HSetRequest, out *HSetResponse) error
  414. SAdd(in *SSetRequest, out *SSetResponse) error
  415. SIsmember(in *SSetRequest, out *SSetResponse) error
  416. SRem(in *SSetRequest, out *SSetResponse) error
  417. LLpush(in *LSetRequest, out *LSetResponse) error
  418. LRpush(in *LSetRequest, out *LSetResponse) error
  419. LRange(in *LRangeRequest, out *HGetListResponse) error
  420. LLen(in *LLenRequest, out *LSetResponse) error
  421. ReduceStock(in *SetRequest, out *SetResponse) error
  422. }
  423. // AcceptRedisServiceClient accepts connections on the listener and serves requests
  424. // for each incoming connection. Accept blocks; the caller typically
  425. // invokes it in a go statement.
  426. func AcceptRedisServiceClient(lis net.Listener, x RedisService) {
  427. srv := rpc.NewServer()
  428. if err := srv.RegisterName("RedisService", x); err != nil {
  429. log.Fatal(err)
  430. }
  431. for {
  432. conn, err := lis.Accept()
  433. if err != nil {
  434. log.Fatalf("lis.Accept(): %v\n", err)
  435. }
  436. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  437. }
  438. }
  439. // RegisterRedisService publish the given RedisService implementation on the server.
  440. func RegisterRedisService(srv *rpc.Server, x RedisService) error {
  441. if err := srv.RegisterName("RedisService", x); err != nil {
  442. return err
  443. }
  444. return nil
  445. }
  446. // NewRedisServiceServer returns a new RedisService Server.
  447. func NewRedisServiceServer(x RedisService) *rpc.Server {
  448. srv := rpc.NewServer()
  449. if err := srv.RegisterName("RedisService", x); err != nil {
  450. log.Fatal(err)
  451. }
  452. return srv
  453. }
  454. // ListenAndServeRedisService listen announces on the local network address laddr
  455. // and serves the given RedisService implementation.
  456. func ListenAndServeRedisService(network, addr string, x RedisService) error {
  457. lis, err := net.Listen(network, addr)
  458. if err != nil {
  459. return err
  460. }
  461. defer lis.Close()
  462. srv := rpc.NewServer()
  463. if err := srv.RegisterName("RedisService", x); err != nil {
  464. return err
  465. }
  466. for {
  467. conn, err := lis.Accept()
  468. if err != nil {
  469. log.Fatalf("lis.Accept(): %v\n", err)
  470. }
  471. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  472. }
  473. }
  474. type RedisServiceClient struct {
  475. *rpc.Client
  476. }
  477. // NewRedisServiceClient returns a RedisService rpc.Client and stub to handle
  478. // requests to the set of RedisService at the other end of the connection.
  479. func NewRedisServiceClient(conn io.ReadWriteCloser) (*RedisServiceClient, *rpc.Client) {
  480. c := rpc.NewClientWithCodec(protorpc.NewClientCodec(conn))
  481. return &RedisServiceClient{c}, c
  482. }
  483. func (c *RedisServiceClient) Get(in *GetRequest, out *GetStringResponse) error {
  484. return c.Call("RedisService.Get", in, out)
  485. }
  486. func (c *RedisServiceClient) Set(in *SetRequest, out *SetResponse) error {
  487. return c.Call("RedisService.Set", in, out)
  488. }
  489. func (c *RedisServiceClient) SetNx(in *SetRequest, out *DelResponse) error {
  490. return c.Call("RedisService.SetNx", in, out)
  491. }
  492. func (c *RedisServiceClient) Del(in *DelRequest, out *DelResponse) error {
  493. return c.Call("RedisService.Del", in, out)
  494. }
  495. func (c *RedisServiceClient) HGet(in *HGetRequest, out *GetStringResponse) error {
  496. return c.Call("RedisService.HGet", in, out)
  497. }
  498. func (c *RedisServiceClient) HSet(in *HSetRequest, out *HSetResponse) error {
  499. return c.Call("RedisService.HSet", in, out)
  500. }
  501. func (c *RedisServiceClient) HDel(in *HDelRequest, out *DelResponse) error {
  502. return c.Call("RedisService.HDel", in, out)
  503. }
  504. func (c *RedisServiceClient) SetExpire(in *SetExpireRequest, out *SetExpireResponse) error {
  505. return c.Call("RedisService.SetExpire", in, out)
  506. }
  507. func (c *RedisServiceClient) HGetAll(in *GetRequest, out *HGetListResponse) error {
  508. return c.Call("RedisService.HGetAll", in, out)
  509. }
  510. func (c *RedisServiceClient) HGetList(in *GetRequest, out *HGetListResponse) error {
  511. return c.Call("RedisService.HGetList", in, out)
  512. }
  513. func (c *RedisServiceClient) HExists(in *HGetRequest, out *DelResponse) error {
  514. return c.Call("RedisService.HExists", in, out)
  515. }
  516. func (c *RedisServiceClient) Exists(in *GetRequest, out *DelResponse) error {
  517. return c.Call("RedisService.Exists", in, out)
  518. }
  519. func (c *RedisServiceClient) HIncrby(in *HSetRequest, out *HSetResponse) error {
  520. return c.Call("RedisService.HIncrby", in, out)
  521. }
  522. func (c *RedisServiceClient) SAdd(in *SSetRequest, out *SSetResponse) error {
  523. return c.Call("RedisService.SAdd", in, out)
  524. }
  525. func (c *RedisServiceClient) SIsmember(in *SSetRequest, out *SSetResponse) error {
  526. return c.Call("RedisService.SIsmember", in, out)
  527. }
  528. func (c *RedisServiceClient) SRem(in *SSetRequest, out *SSetResponse) error {
  529. return c.Call("RedisService.SRem", in, out)
  530. }
  531. func (c *RedisServiceClient) LLpush(in *LSetRequest, out *LSetResponse) error {
  532. return c.Call("RedisService.LLpush", in, out)
  533. }
  534. func (c *RedisServiceClient) LRpush(in *LSetRequest, out *LSetResponse) error {
  535. return c.Call("RedisService.LRpush", in, out)
  536. }
  537. func (c *RedisServiceClient) LRange(in *LRangeRequest, out *HGetListResponse) error {
  538. return c.Call("RedisService.LRange", in, out)
  539. }
  540. func (c *RedisServiceClient) LLen(in *LLenRequest, out *LSetResponse) error {
  541. return c.Call("RedisService.LLen", in, out)
  542. }
  543. func (c *RedisServiceClient) ReduceStock(in *SetRequest, out *SetResponse) error {
  544. return c.Call("RedisService.ReduceStock", in, out)
  545. }
  546. // DialRedisService connects to an RedisService at the specified network address.
  547. func DialRedisService(network, addr string) (*RedisServiceClient, *rpc.Client, error) {
  548. c, err := protorpc.Dial(network, addr)
  549. if err != nil {
  550. return nil, nil, err
  551. }
  552. return &RedisServiceClient{c}, c, nil
  553. }
  554. // DialRedisServiceTimeout connects to an RedisService at the specified network address.
  555. func DialRedisServiceTimeout(network, addr string,
  556. timeout time.Duration) (*RedisServiceClient, *rpc.Client, error) {
  557. c, err := protorpc.DialTimeout(network, addr, timeout)
  558. if err != nil {
  559. return nil, nil, err
  560. }
  561. return &RedisServiceClient{c}, c, nil
  562. }