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.

443 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. }
  277. // AcceptRedisServiceClient accepts connections on the listener and serves requests
  278. // for each incoming connection. Accept blocks; the caller typically
  279. // invokes it in a go statement.
  280. func AcceptRedisServiceClient(lis net.Listener, x RedisService) {
  281. srv := rpc.NewServer()
  282. if err := srv.RegisterName("RedisService", x); err != nil {
  283. log.Fatal(err)
  284. }
  285. for {
  286. conn, err := lis.Accept()
  287. if err != nil {
  288. log.Fatalf("lis.Accept(): %v\n", err)
  289. }
  290. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  291. }
  292. }
  293. // RegisterRedisService publish the given RedisService implementation on the server.
  294. func RegisterRedisService(srv *rpc.Server, x RedisService) error {
  295. if err := srv.RegisterName("RedisService", x); err != nil {
  296. return err
  297. }
  298. return nil
  299. }
  300. // NewRedisServiceServer returns a new RedisService Server.
  301. func NewRedisServiceServer(x RedisService) *rpc.Server {
  302. srv := rpc.NewServer()
  303. if err := srv.RegisterName("RedisService", x); err != nil {
  304. log.Fatal(err)
  305. }
  306. return srv
  307. }
  308. // ListenAndServeRedisService listen announces on the local network address laddr
  309. // and serves the given RedisService implementation.
  310. func ListenAndServeRedisService(network, addr string, x RedisService) error {
  311. lis, err := net.Listen(network, addr)
  312. if err != nil {
  313. return err
  314. }
  315. defer lis.Close()
  316. srv := rpc.NewServer()
  317. if err := srv.RegisterName("RedisService", x); err != nil {
  318. return err
  319. }
  320. for {
  321. conn, err := lis.Accept()
  322. if err != nil {
  323. log.Fatalf("lis.Accept(): %v\n", err)
  324. }
  325. go srv.ServeCodec(protorpc.NewServerCodec(conn))
  326. }
  327. }
  328. type RedisServiceClient struct {
  329. *rpc.Client
  330. }
  331. // NewRedisServiceClient returns a RedisService rpc.Client and stub to handle
  332. // requests to the set of RedisService at the other end of the connection.
  333. func NewRedisServiceClient(conn io.ReadWriteCloser) (*RedisServiceClient, *rpc.Client) {
  334. c := rpc.NewClientWithCodec(protorpc.NewClientCodec(conn))
  335. return &RedisServiceClient{c}, c
  336. }
  337. func (c *RedisServiceClient) Get(in *GetRequest, out *GetStringResponse) error {
  338. return c.Call("RedisService.Get", in, out)
  339. }
  340. func (c *RedisServiceClient) Set(in *SetRequest, out *SetResponse) error {
  341. return c.Call("RedisService.Set", in, out)
  342. }
  343. func (c *RedisServiceClient) Del(in *DelRequest, out *DelResponse) error {
  344. return c.Call("RedisService.Del", in, out)
  345. }
  346. func (c *RedisServiceClient) HGet(in *HGetRequest, out *GetStringResponse) error {
  347. return c.Call("RedisService.HGet", in, out)
  348. }
  349. func (c *RedisServiceClient) HSet(in *HSetRequest, out *HSetResponse) error {
  350. return c.Call("RedisService.HSet", in, out)
  351. }
  352. func (c *RedisServiceClient) HDel(in *HDelRequest, out *DelResponse) error {
  353. return c.Call("RedisService.HDel", in, out)
  354. }
  355. func (c *RedisServiceClient) SetExpire(in *SetExpireRequest, out *SetExpireResponse) error {
  356. return c.Call("RedisService.SetExpire", in, out)
  357. }
  358. func (c *RedisServiceClient) HGetAll(in *GetRequest, out *HGetListResponse) error {
  359. return c.Call("RedisService.HGetAll", in, out)
  360. }
  361. // DialRedisService connects to an RedisService at the specified network address.
  362. func DialRedisService(network, addr string) (*RedisServiceClient, *rpc.Client, error) {
  363. c, err := protorpc.Dial(network, addr)
  364. if err != nil {
  365. return nil, nil, err
  366. }
  367. return &RedisServiceClient{c}, c, nil
  368. }
  369. // DialRedisServiceTimeout connects to an RedisService at the specified network address.
  370. func DialRedisServiceTimeout(network, addr string,
  371. timeout time.Duration) (*RedisServiceClient, *rpc.Client, error) {
  372. c, err := protorpc.DialTimeout(network, addr, timeout)
  373. if err != nil {
  374. return nil, nil, err
  375. }
  376. return &RedisServiceClient{c}, c, nil
  377. }