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.

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