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.

843 lines
23 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 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. AddRequest
  30. AddResponse
  31. ZSetRequest
  32. ZSetResponse
  33. ZRangeRequest
  34. ZScanRequest
  35. */
  36. package redisrpc
  37. import proto "github.com/chai2010/protorpc/proto"
  38. import math "math"
  39. import "io"
  40. import "log"
  41. import "net"
  42. import "net/rpc"
  43. import "time"
  44. import protorpc "github.com/chai2010/protorpc"
  45. // Reference imports to suppress errors if they are not otherwise used.
  46. var _ = proto.Marshal
  47. var _ = math.Inf
  48. // 使用key查询
  49. type GetRequest struct {
  50. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  51. XXX_unrecognized []byte `json:"-"`
  52. }
  53. func (m *GetRequest) Reset() { *m = GetRequest{} }
  54. func (m *GetRequest) String() string { return proto.CompactTextString(m) }
  55. func (*GetRequest) ProtoMessage() {}
  56. func (m *GetRequest) GetKey() string {
  57. if m != nil && m.Key != nil {
  58. return *m.Key
  59. }
  60. return ""
  61. }
  62. // 设置key
  63. type SetRequest struct {
  64. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  65. Value *string `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
  66. Ttl *int64 `protobuf:"varint,3,opt,name=ttl" json:"ttl,omitempty"`
  67. XXX_unrecognized []byte `json:"-"`
  68. }
  69. func (m *SetRequest) Reset() { *m = SetRequest{} }
  70. func (m *SetRequest) String() string { return proto.CompactTextString(m) }
  71. func (*SetRequest) ProtoMessage() {}
  72. func (m *SetRequest) GetKey() string {
  73. if m != nil && m.Key != nil {
  74. return *m.Key
  75. }
  76. return ""
  77. }
  78. func (m *SetRequest) GetValue() string {
  79. if m != nil && m.Value != nil {
  80. return *m.Value
  81. }
  82. return ""
  83. }
  84. func (m *SetRequest) GetTtl() int64 {
  85. if m != nil && m.Ttl != nil {
  86. return *m.Ttl
  87. }
  88. return 0
  89. }
  90. type DelRequest struct {
  91. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  92. XXX_unrecognized []byte `json:"-"`
  93. }
  94. func (m *DelRequest) Reset() { *m = DelRequest{} }
  95. func (m *DelRequest) String() string { return proto.CompactTextString(m) }
  96. func (*DelRequest) ProtoMessage() {}
  97. func (m *DelRequest) GetKey() string {
  98. if m != nil && m.Key != nil {
  99. return *m.Key
  100. }
  101. return ""
  102. }
  103. // 使用hash key查询
  104. type HGetRequest struct {
  105. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  106. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  107. XXX_unrecognized []byte `json:"-"`
  108. }
  109. func (m *HGetRequest) Reset() { *m = HGetRequest{} }
  110. func (m *HGetRequest) String() string { return proto.CompactTextString(m) }
  111. func (*HGetRequest) ProtoMessage() {}
  112. func (m *HGetRequest) GetKey() string {
  113. if m != nil && m.Key != nil {
  114. return *m.Key
  115. }
  116. return ""
  117. }
  118. func (m *HGetRequest) GetField() string {
  119. if m != nil && m.Field != nil {
  120. return *m.Field
  121. }
  122. return ""
  123. }
  124. // 设置hash key
  125. type HSetRequest struct {
  126. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  127. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  128. Value *string `protobuf:"bytes,3,opt,name=value" json:"value,omitempty"`
  129. XXX_unrecognized []byte `json:"-"`
  130. }
  131. func (m *HSetRequest) Reset() { *m = HSetRequest{} }
  132. func (m *HSetRequest) String() string { return proto.CompactTextString(m) }
  133. func (*HSetRequest) ProtoMessage() {}
  134. func (m *HSetRequest) GetKey() string {
  135. if m != nil && m.Key != nil {
  136. return *m.Key
  137. }
  138. return ""
  139. }
  140. func (m *HSetRequest) GetField() string {
  141. if m != nil && m.Field != nil {
  142. return *m.Field
  143. }
  144. return ""
  145. }
  146. func (m *HSetRequest) GetValue() string {
  147. if m != nil && m.Value != nil {
  148. return *m.Value
  149. }
  150. return ""
  151. }
  152. // 删除hash key
  153. type HDelRequest struct {
  154. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  155. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  156. XXX_unrecognized []byte `json:"-"`
  157. }
  158. func (m *HDelRequest) Reset() { *m = HDelRequest{} }
  159. func (m *HDelRequest) String() string { return proto.CompactTextString(m) }
  160. func (*HDelRequest) ProtoMessage() {}
  161. func (m *HDelRequest) GetKey() string {
  162. if m != nil && m.Key != nil {
  163. return *m.Key
  164. }
  165. return ""
  166. }
  167. func (m *HDelRequest) GetField() string {
  168. if m != nil && m.Field != nil {
  169. return *m.Field
  170. }
  171. return ""
  172. }
  173. // 有效期
  174. type SetExpireRequest struct {
  175. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  176. Expire *int64 `protobuf:"varint,2,opt,name=expire" json:"expire,omitempty"`
  177. XXX_unrecognized []byte `json:"-"`
  178. }
  179. func (m *SetExpireRequest) Reset() { *m = SetExpireRequest{} }
  180. func (m *SetExpireRequest) String() string { return proto.CompactTextString(m) }
  181. func (*SetExpireRequest) ProtoMessage() {}
  182. func (m *SetExpireRequest) GetKey() string {
  183. if m != nil && m.Key != nil {
  184. return *m.Key
  185. }
  186. return ""
  187. }
  188. func (m *SetExpireRequest) GetExpire() int64 {
  189. if m != nil && m.Expire != nil {
  190. return *m.Expire
  191. }
  192. return 0
  193. }
  194. // 使用key查询响应结构
  195. type GetStringResponse struct {
  196. Value *string `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"`
  197. XXX_unrecognized []byte `json:"-"`
  198. }
  199. func (m *GetStringResponse) Reset() { *m = GetStringResponse{} }
  200. func (m *GetStringResponse) String() string { return proto.CompactTextString(m) }
  201. func (*GetStringResponse) ProtoMessage() {}
  202. func (m *GetStringResponse) GetValue() string {
  203. if m != nil && m.Value != nil {
  204. return *m.Value
  205. }
  206. return ""
  207. }
  208. // 使用key查询响应结构
  209. type HGetListResponse struct {
  210. List []byte `protobuf:"bytes,1,opt,name=list" json:"list,omitempty"`
  211. XXX_unrecognized []byte `json:"-"`
  212. }
  213. func (m *HGetListResponse) Reset() { *m = HGetListResponse{} }
  214. func (m *HGetListResponse) String() string { return proto.CompactTextString(m) }
  215. func (*HGetListResponse) ProtoMessage() {}
  216. func (m *HGetListResponse) GetList() []byte {
  217. if m != nil {
  218. return m.List
  219. }
  220. return nil
  221. }
  222. // 设置key响应结构
  223. type SetResponse struct {
  224. Ret *string `protobuf:"bytes,1,opt,name=ret" json:"ret,omitempty"`
  225. XXX_unrecognized []byte `json:"-"`
  226. }
  227. func (m *SetResponse) Reset() { *m = SetResponse{} }
  228. func (m *SetResponse) String() string { return proto.CompactTextString(m) }
  229. func (*SetResponse) ProtoMessage() {}
  230. func (m *SetResponse) GetRet() string {
  231. if m != nil && m.Ret != nil {
  232. return *m.Ret
  233. }
  234. return ""
  235. }
  236. // 删除key响应结构
  237. type DelResponse struct {
  238. Ret *int64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  239. XXX_unrecognized []byte `json:"-"`
  240. }
  241. func (m *DelResponse) Reset() { *m = DelResponse{} }
  242. func (m *DelResponse) String() string { return proto.CompactTextString(m) }
  243. func (*DelResponse) ProtoMessage() {}
  244. func (m *DelResponse) GetRet() int64 {
  245. if m != nil && m.Ret != nil {
  246. return *m.Ret
  247. }
  248. return 0
  249. }
  250. // 设置key响应结构
  251. type HSetResponse struct {
  252. Ret *int64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  253. XXX_unrecognized []byte `json:"-"`
  254. }
  255. func (m *HSetResponse) Reset() { *m = HSetResponse{} }
  256. func (m *HSetResponse) String() string { return proto.CompactTextString(m) }
  257. func (*HSetResponse) ProtoMessage() {}
  258. func (m *HSetResponse) GetRet() int64 {
  259. if m != nil && m.Ret != nil {
  260. return *m.Ret
  261. }
  262. return 0
  263. }
  264. // 设置key有效期
  265. type SetExpireResponse struct {
  266. Ret *int64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  267. XXX_unrecognized []byte `json:"-"`
  268. }
  269. func (m *SetExpireResponse) Reset() { *m = SetExpireResponse{} }
  270. func (m *SetExpireResponse) String() string { return proto.CompactTextString(m) }
  271. func (*SetExpireResponse) ProtoMessage() {}
  272. func (m *SetExpireResponse) GetRet() int64 {
  273. if m != nil && m.Ret != nil {
  274. return *m.Ret
  275. }
  276. return 0
  277. }
  278. // 集合添加值
  279. type SSetRequest struct {
  280. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  281. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  282. XXX_unrecognized []byte `json:"-"`
  283. }
  284. func (m *SSetRequest) Reset() { *m = SSetRequest{} }
  285. func (m *SSetRequest) String() string { return proto.CompactTextString(m) }
  286. func (*SSetRequest) ProtoMessage() {}
  287. func (m *SSetRequest) GetKey() string {
  288. if m != nil && m.Key != nil {
  289. return *m.Key
  290. }
  291. return ""
  292. }
  293. func (m *SSetRequest) GetField() string {
  294. if m != nil && m.Field != nil {
  295. return *m.Field
  296. }
  297. return ""
  298. }
  299. // 集合添加值
  300. type SMembersRequest struct {
  301. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  302. XXX_unrecognized []byte `json:"-"`
  303. }
  304. func (m *SMembersRequest) Reset() { *m = SMembersRequest{} }
  305. func (m *SMembersRequest) String() string { return proto.CompactTextString(m) }
  306. func (*SMembersRequest) ProtoMessage() {}
  307. func (m *SMembersRequest) GetKey() string {
  308. if m != nil && m.Key != nil {
  309. return *m.Key
  310. }
  311. return ""
  312. }
  313. // 设置响应结构
  314. type SSetResponse struct {
  315. Ret *int64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  316. XXX_unrecognized []byte `json:"-"`
  317. }
  318. func (m *SSetResponse) Reset() { *m = SSetResponse{} }
  319. func (m *SSetResponse) String() string { return proto.CompactTextString(m) }
  320. func (*SSetResponse) ProtoMessage() {}
  321. func (m *SSetResponse) GetRet() int64 {
  322. if m != nil && m.Ret != nil {
  323. return *m.Ret
  324. }
  325. return 0
  326. }
  327. // 列表添加值
  328. type LSetRequest struct {
  329. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  330. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  331. XXX_unrecognized []byte `json:"-"`
  332. }
  333. func (m *LSetRequest) Reset() { *m = LSetRequest{} }
  334. func (m *LSetRequest) String() string { return proto.CompactTextString(m) }
  335. func (*LSetRequest) ProtoMessage() {}
  336. func (m *LSetRequest) GetKey() string {
  337. if m != nil && m.Key != nil {
  338. return *m.Key
  339. }
  340. return ""
  341. }
  342. func (m *LSetRequest) GetField() string {
  343. if m != nil && m.Field != nil {
  344. return *m.Field
  345. }
  346. return ""
  347. }
  348. // 设置key响应结构
  349. type LSetResponse struct {
  350. Ret *int64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  351. XXX_unrecognized []byte `json:"-"`
  352. }
  353. func (m *LSetResponse) Reset() { *m = LSetResponse{} }
  354. func (m *LSetResponse) String() string { return proto.CompactTextString(m) }
  355. func (*LSetResponse) ProtoMessage() {}
  356. func (m *LSetResponse) GetRet() int64 {
  357. if m != nil && m.Ret != nil {
  358. return *m.Ret
  359. }
  360. return 0
  361. }
  362. // 列表取值
  363. type LRangeRequest struct {
  364. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  365. Start *int64 `protobuf:"varint,2,opt,name=start" json:"start,omitempty"`
  366. Stop *int64 `protobuf:"varint,3,opt,name=stop" json:"stop,omitempty"`
  367. XXX_unrecognized []byte `json:"-"`
  368. }
  369. func (m *LRangeRequest) Reset() { *m = LRangeRequest{} }
  370. func (m *LRangeRequest) String() string { return proto.CompactTextString(m) }
  371. func (*LRangeRequest) ProtoMessage() {}
  372. func (m *LRangeRequest) GetKey() string {
  373. if m != nil && m.Key != nil {
  374. return *m.Key
  375. }
  376. return ""
  377. }
  378. func (m *LRangeRequest) GetStart() int64 {
  379. if m != nil && m.Start != nil {
  380. return *m.Start
  381. }
  382. return 0
  383. }
  384. func (m *LRangeRequest) GetStop() int64 {
  385. if m != nil && m.Stop != nil {
  386. return *m.Stop
  387. }
  388. return 0
  389. }
  390. // 列表长度
  391. type LLenRequest struct {
  392. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  393. XXX_unrecognized []byte `json:"-"`
  394. }
  395. func (m *LLenRequest) Reset() { *m = LLenRequest{} }
  396. func (m *LLenRequest) String() string { return proto.CompactTextString(m) }
  397. func (*LLenRequest) ProtoMessage() {}
  398. func (m *LLenRequest) GetKey() string {
  399. if m != nil && m.Key != nil {
  400. return *m.Key
  401. }
  402. return ""
  403. }
  404. // 数值增加
  405. type AddRequest struct {
  406. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  407. Value *int64 `protobuf:"varint,2,opt,name=value" json:"value,omitempty"`
  408. XXX_unrecognized []byte `json:"-"`
  409. }
  410. func (m *AddRequest) Reset() { *m = AddRequest{} }
  411. func (m *AddRequest) String() string { return proto.CompactTextString(m) }
  412. func (*AddRequest) ProtoMessage() {}
  413. func (m *AddRequest) GetKey() string {
  414. if m != nil && m.Key != nil {
  415. return *m.Key
  416. }
  417. return ""
  418. }
  419. func (m *AddRequest) GetValue() int64 {
  420. if m != nil && m.Value != nil {
  421. return *m.Value
  422. }
  423. return 0
  424. }
  425. type AddResponse struct {
  426. Ret *int64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  427. XXX_unrecognized []byte `json:"-"`
  428. }
  429. func (m *AddResponse) Reset() { *m = AddResponse{} }
  430. func (m *AddResponse) String() string { return proto.CompactTextString(m) }
  431. func (*AddResponse) ProtoMessage() {}
  432. func (m *AddResponse) GetRet() int64 {
  433. if m != nil && m.Ret != nil {
  434. return *m.Ret
  435. }
  436. return 0
  437. }
  438. // 有序集合添加值
  439. type ZSetRequest struct {
  440. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  441. Score *string `protobuf:"bytes,2,opt,name=score" json:"score,omitempty"`
  442. Member *string `protobuf:"bytes,3,opt,name=member" json:"member,omitempty"`
  443. XXX_unrecognized []byte `json:"-"`
  444. }
  445. func (m *ZSetRequest) Reset() { *m = ZSetRequest{} }
  446. func (m *ZSetRequest) String() string { return proto.CompactTextString(m) }
  447. func (*ZSetRequest) ProtoMessage() {}
  448. func (m *ZSetRequest) GetKey() string {
  449. if m != nil && m.Key != nil {
  450. return *m.Key
  451. }
  452. return ""
  453. }
  454. func (m *ZSetRequest) GetScore() string {
  455. if m != nil && m.Score != nil {
  456. return *m.Score
  457. }
  458. return ""
  459. }
  460. func (m *ZSetRequest) GetMember() string {
  461. if m != nil && m.Member != nil {
  462. return *m.Member
  463. }
  464. return ""
  465. }
  466. // 设置响应结构
  467. type ZSetResponse struct {
  468. Ret *int64 `protobuf:"varint,1,opt,name=ret" json:"ret,omitempty"`
  469. XXX_unrecognized []byte `json:"-"`
  470. }
  471. func (m *ZSetResponse) Reset() { *m = ZSetResponse{} }
  472. func (m *ZSetResponse) String() string { return proto.CompactTextString(m) }
  473. func (*ZSetResponse) ProtoMessage() {}
  474. func (m *ZSetResponse) GetRet() int64 {
  475. if m != nil && m.Ret != nil {
  476. return *m.Ret
  477. }
  478. return 0
  479. }
  480. // 有序集合取值
  481. type ZRangeRequest struct {
  482. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  483. Start *int64 `protobuf:"varint,2,opt,name=start" json:"start,omitempty"`
  484. Stop *int64 `protobuf:"varint,3,opt,name=stop" json:"stop,omitempty"`
  485. XXX_unrecognized []byte `json:"-"`
  486. }
  487. func (m *ZRangeRequest) Reset() { *m = ZRangeRequest{} }
  488. func (m *ZRangeRequest) String() string { return proto.CompactTextString(m) }
  489. func (*ZRangeRequest) ProtoMessage() {}
  490. func (m *ZRangeRequest) GetKey() string {
  491. if m != nil && m.Key != nil {
  492. return *m.Key
  493. }
  494. return ""
  495. }
  496. func (m *ZRangeRequest) GetStart() int64 {
  497. if m != nil && m.Start != nil {
  498. return *m.Start
  499. }
  500. return 0
  501. }
  502. func (m *ZRangeRequest) GetStop() int64 {
  503. if m != nil && m.Stop != nil {
  504. return *m.Stop
  505. }
  506. return 0
  507. }
  508. type ZScanRequest struct {
  509. Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
  510. Field *string `protobuf:"bytes,2,opt,name=field" json:"field,omitempty"`
  511. Len *int64 `protobuf:"varint,3,opt,name=len" json:"len,omitempty"`
  512. XXX_unrecognized []byte `json:"-"`
  513. }
  514. func (m *ZScanRequest) Reset() { *m = ZScanRequest{} }
  515. func (m *ZScanRequest) String() string { return proto.CompactTextString(m) }
  516. func (*ZScanRequest) ProtoMessage() {}
  517. func (m *ZScanRequest) GetKey() string {
  518. if m != nil && m.Key != nil {
  519. return *m.Key
  520. }
  521. return ""
  522. }
  523. func (m *ZScanRequest) GetField() string {
  524. if m != nil && m.Field != nil {
  525. return *m.Field
  526. }
  527. return ""
  528. }
  529. func (m *ZScanRequest) GetLen() int64 {
  530. if m != nil && m.Len != nil {
  531. return *m.Len
  532. }
  533. return 0
  534. }
  535. func init() {
  536. }
  537. type RedisService interface {
  538. Get(in *GetRequest, out *GetStringResponse) error
  539. Set(in *SetRequest, out *SetResponse) error
  540. SetNx(in *SetRequest, out *DelResponse) error
  541. Del(in *DelRequest, out *DelResponse) error
  542. HGet(in *HGetRequest, out *GetStringResponse) error
  543. HSet(in *HSetRequest, out *HSetResponse) error
  544. HDel(in *HDelRequest, out *DelResponse) error
  545. SetExpire(in *SetExpireRequest, out *SetExpireResponse) error
  546. HGetAll(in *GetRequest, out *HGetListResponse) error
  547. HGetList(in *GetRequest, out *HGetListResponse) error
  548. HExists(in *HGetRequest, out *DelResponse) error
  549. Exists(in *GetRequest, out *DelResponse) error
  550. HIncrby(in *HSetRequest, out *HSetResponse) error
  551. SAdd(in *SSetRequest, out *SSetResponse) error
  552. SIsmember(in *SSetRequest, out *SSetResponse) error
  553. SRem(in *SSetRequest, out *SSetResponse) error
  554. SCard(in *SMembersRequest, out *SSetResponse) error
  555. LLpush(in *LSetRequest, out *LSetResponse) error
  556. LRpush(in *LSetRequest, out *LSetResponse) error
  557. LRange(in *LRangeRequest, out *HGetListResponse) error
  558. LLen(in *LLenRequest, out *LSetResponse) error
  559. ReduceStock(in *SetRequest, out *SetResponse) error
  560. Incrby(in *AddRequest, out *AddResponse) error
  561. Decrby(in *AddRequest, out *AddResponse) error
  562. ZAdd(in *ZSetRequest, out *ZSetResponse) error
  563. ZIncrBy(in *ZSetRequest, out *ZSetResponse) error
  564. ZRange(in *ZRangeRequest, out *HGetListResponse) error
  565. ZScan(in *ZScanRequest, out *HGetListResponse) error
  566. }
  567. // AcceptRedisServiceClient accepts connections on the listener and serves requests
  568. // for each incoming connection. Accept blocks; the caller typically
  569. // invokes it in a go statement.
  570. func AcceptRedisServiceClient(lis net.Listener, x RedisService) {
  571. srv := rpc.NewServer()
  572. if err := srv.RegisterName("RedisService", x); err != nil {
  573. log.Fatal(err)
  574. }
  575. for {
  576. conn, err := lis.Accept()
  577. if err != nil {
  578. log.Fatalf("lis.Accept(): %v\n", err)
  579. }
  580. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  581. }
  582. }
  583. // RegisterRedisService publish the given RedisService implementation on the server.
  584. func RegisterRedisService(srv *rpc.Server, x RedisService) error {
  585. if err := srv.RegisterName("RedisService", x); err != nil {
  586. return err
  587. }
  588. return nil
  589. }
  590. // NewRedisServiceServer returns a new RedisService Server.
  591. func NewRedisServiceServer(x RedisService) *rpc.Server {
  592. srv := rpc.NewServer()
  593. if err := srv.RegisterName("RedisService", x); err != nil {
  594. log.Fatal(err)
  595. }
  596. return srv
  597. }
  598. // ListenAndServeRedisService listen announces on the local network address laddr
  599. // and serves the given RedisService implementation.
  600. func ListenAndServeRedisService(network, addr string, x RedisService) error {
  601. lis, err := net.Listen(network, addr)
  602. if err != nil {
  603. return err
  604. }
  605. defer lis.Close()
  606. srv := rpc.NewServer()
  607. if err := srv.RegisterName("RedisService", x); err != nil {
  608. return err
  609. }
  610. for {
  611. conn, err := lis.Accept()
  612. if err != nil {
  613. log.Fatalf("lis.Accept(): %v\n", err)
  614. }
  615. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  616. }
  617. }
  618. type RedisServiceClient struct {
  619. *rpc.Client
  620. }
  621. // NewRedisServiceClient returns a RedisService rpc.Client and stub to handle
  622. // requests to the set of RedisService at the other end of the connection.
  623. func NewRedisServiceClient(conn io.ReadWriteCloser) (*RedisServiceClient, *rpc.Client) {
  624. c := rpc.NewClientWithCodec(protorpc.NewClientCodec(conn))
  625. return &RedisServiceClient{c}, c
  626. }
  627. func (c *RedisServiceClient) Get(in *GetRequest, out *GetStringResponse) error {
  628. return c.Call("RedisService.Get", in, out)
  629. }
  630. func (c *RedisServiceClient) Set(in *SetRequest, out *SetResponse) error {
  631. return c.Call("RedisService.Set", in, out)
  632. }
  633. func (c *RedisServiceClient) SetNx(in *SetRequest, out *DelResponse) error {
  634. return c.Call("RedisService.SetNx", in, out)
  635. }
  636. func (c *RedisServiceClient) Del(in *DelRequest, out *DelResponse) error {
  637. return c.Call("RedisService.Del", in, out)
  638. }
  639. func (c *RedisServiceClient) HGet(in *HGetRequest, out *GetStringResponse) error {
  640. return c.Call("RedisService.HGet", in, out)
  641. }
  642. func (c *RedisServiceClient) HSet(in *HSetRequest, out *HSetResponse) error {
  643. return c.Call("RedisService.HSet", in, out)
  644. }
  645. func (c *RedisServiceClient) HDel(in *HDelRequest, out *DelResponse) error {
  646. return c.Call("RedisService.HDel", in, out)
  647. }
  648. func (c *RedisServiceClient) SetExpire(in *SetExpireRequest, out *SetExpireResponse) error {
  649. return c.Call("RedisService.SetExpire", in, out)
  650. }
  651. func (c *RedisServiceClient) HGetAll(in *GetRequest, out *HGetListResponse) error {
  652. return c.Call("RedisService.HGetAll", in, out)
  653. }
  654. func (c *RedisServiceClient) HGetList(in *GetRequest, out *HGetListResponse) error {
  655. return c.Call("RedisService.HGetList", in, out)
  656. }
  657. func (c *RedisServiceClient) HExists(in *HGetRequest, out *DelResponse) error {
  658. return c.Call("RedisService.HExists", in, out)
  659. }
  660. func (c *RedisServiceClient) Exists(in *GetRequest, out *DelResponse) error {
  661. return c.Call("RedisService.Exists", in, out)
  662. }
  663. func (c *RedisServiceClient) HIncrby(in *HSetRequest, out *HSetResponse) error {
  664. return c.Call("RedisService.HIncrby", in, out)
  665. }
  666. func (c *RedisServiceClient) SAdd(in *SSetRequest, out *SSetResponse) error {
  667. return c.Call("RedisService.SAdd", in, out)
  668. }
  669. func (c *RedisServiceClient) SIsmember(in *SSetRequest, out *SSetResponse) error {
  670. return c.Call("RedisService.SIsmember", in, out)
  671. }
  672. func (c *RedisServiceClient) SRem(in *SSetRequest, out *SSetResponse) error {
  673. return c.Call("RedisService.SRem", in, out)
  674. }
  675. func (c *RedisServiceClient) SCard(in *SMembersRequest, out *SSetResponse) error {
  676. return c.Call("RedisService.SCard", in, out)
  677. }
  678. func (c *RedisServiceClient) LLpush(in *LSetRequest, out *LSetResponse) error {
  679. return c.Call("RedisService.LLpush", in, out)
  680. }
  681. func (c *RedisServiceClient) LRpush(in *LSetRequest, out *LSetResponse) error {
  682. return c.Call("RedisService.LRpush", in, out)
  683. }
  684. func (c *RedisServiceClient) LRange(in *LRangeRequest, out *HGetListResponse) error {
  685. return c.Call("RedisService.LRange", in, out)
  686. }
  687. func (c *RedisServiceClient) LLen(in *LLenRequest, out *LSetResponse) error {
  688. return c.Call("RedisService.LLen", in, out)
  689. }
  690. func (c *RedisServiceClient) ReduceStock(in *SetRequest, out *SetResponse) error {
  691. return c.Call("RedisService.ReduceStock", in, out)
  692. }
  693. func (c *RedisServiceClient) Incrby(in *AddRequest, out *AddResponse) error {
  694. return c.Call("RedisService.Incrby", in, out)
  695. }
  696. func (c *RedisServiceClient) Decrby(in *AddRequest, out *AddResponse) error {
  697. return c.Call("RedisService.Decrby", in, out)
  698. }
  699. func (c *RedisServiceClient) ZAdd(in *ZSetRequest, out *ZSetResponse) error {
  700. return c.Call("RedisService.ZAdd", in, out)
  701. }
  702. func (c *RedisServiceClient) ZIncrBy(in *ZSetRequest, out *ZSetResponse) error {
  703. return c.Call("RedisService.ZIncrBy", in, out)
  704. }
  705. func (c *RedisServiceClient) ZRange(in *ZRangeRequest, out *HGetListResponse) error {
  706. return c.Call("RedisService.ZRange", in, out)
  707. }
  708. func (c *RedisServiceClient) ZScan(in *ZScanRequest, out *HGetListResponse) error {
  709. return c.Call("RedisService.ZScan", in, out)
  710. }
  711. // DialRedisService connects to an RedisService at the specified network address.
  712. func DialRedisService(network, addr string) (*RedisServiceClient, *rpc.Client, error) {
  713. c, err := protorpc.Dial(network, addr)
  714. if err != nil {
  715. return nil, nil, err
  716. }
  717. return &RedisServiceClient{c}, c, nil
  718. }
  719. // DialRedisServiceTimeout connects to an RedisService at the specified network address.
  720. func DialRedisServiceTimeout(network, addr string,
  721. timeout time.Duration) (*RedisServiceClient, *rpc.Client, error) {
  722. c, err := protorpc.DialTimeout(network, addr, timeout)
  723. if err != nil {
  724. return nil, nil, err
  725. }
  726. return &RedisServiceClient{c}, c, nil
  727. }