chore(service): update service
This commit is contained in:
parent
dcada2f2fe
commit
047c910278
|
@ -59,6 +59,33 @@ func (d *Dao) ExecMessage(message protobuf.Message) error {
|
|||
case *proto.RPushXRequest:
|
||||
_, err := d.RPushX(req.Key, req.Values)
|
||||
return err
|
||||
case *proto.HDelRequest:
|
||||
_, err := d.HDel(req.Key, req.HKeys)
|
||||
return err
|
||||
case *proto.HExistsRequest:
|
||||
_, err := d.HExists(req.Key, req.HKey)
|
||||
return err
|
||||
case *proto.HGetRequest:
|
||||
_, err := d.HGet(req.Key, req.HKeys)
|
||||
return err
|
||||
case *proto.HGetAllRequest:
|
||||
_, err := d.HGetAll(req.Key)
|
||||
return err
|
||||
case *proto.HIncrByRequest:
|
||||
_, err := d.HIncrBy(req.Key, req.HKeys)
|
||||
return err
|
||||
case *proto.HKeysRequest:
|
||||
_, err := d.HKeys(req.Key)
|
||||
return err
|
||||
case *proto.HLenRequest:
|
||||
_, err := d.HLen(req.Key)
|
||||
return err
|
||||
case *proto.HSetRequest:
|
||||
_, err := d.HSet(req.Key, req.Items)
|
||||
return err
|
||||
case *proto.HSetXRequest:
|
||||
_, err := d.HSetX(req.Key, req.Items)
|
||||
return err
|
||||
case *proto.SetRequest:
|
||||
_, err := d.Set(req.Key, req.Val)
|
||||
return err
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package dao
|
||||
|
||||
import "gitee.com/wheat-os/wheatCache/pkg/proto"
|
||||
|
||||
func (d *Dao) HDel(key *proto.BaseKey, hKeys []string) (*proto.HDelResponse, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (d *Dao) HExists(_ *proto.BaseKey, _ string) (*proto.HExistsResponse, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (d *Dao) HGet(_ *proto.BaseKey, _ []string) (*proto.HGetResponse, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (d *Dao) HGetAll(_ *proto.BaseKey) (*proto.HGetAllResponse, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (d *Dao) HIncrBy(_ *proto.BaseKey, _ []string) (*proto.HIncrByResponse, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (d *Dao) HKeys(_ *proto.BaseKey) (*proto.HKeysResponse, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (d *Dao) HLen(_ *proto.BaseKey) (*proto.HLenResponse, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (d *Dao) HSet(_ *proto.BaseKey, _ map[string]string) (*proto.HSetResponse, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (d *Dao) HSetX(_ *proto.BaseKey, _ map[string]string) (*proto.HSetXResponse, error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
|
@ -21,6 +21,15 @@ type Interface interface {
|
|||
LTrim(*proto.BaseKey, int32, int32) (*proto.LTrimResponse, error)
|
||||
RPush(*proto.BaseKey, []string) (*proto.RPushResponse, error)
|
||||
RPushX(*proto.BaseKey, []string) (*proto.RPushXResponse, error)
|
||||
HDel(*proto.BaseKey, []string) (*proto.HDelResponse, error)
|
||||
HExists(*proto.BaseKey, string) (*proto.HExistsResponse, error)
|
||||
HGet(*proto.BaseKey, []string) (*proto.HGetResponse, error)
|
||||
HGetAll(*proto.BaseKey) (*proto.HGetAllResponse, error)
|
||||
HIncrBy(*proto.BaseKey, []string) (*proto.HIncrByResponse, error)
|
||||
HKeys(*proto.BaseKey) (*proto.HKeysResponse, error)
|
||||
HLen(*proto.BaseKey) (*proto.HLenResponse, error)
|
||||
HSet(*proto.BaseKey, map[string]string) (*proto.HSetResponse, error)
|
||||
HSetX(*proto.BaseKey, map[string]string) (*proto.HSetXResponse, error)
|
||||
Set(*proto.BaseKey, string) (*proto.SetResponse, error)
|
||||
Get(*proto.BaseKey) (*proto.GetResponse, error)
|
||||
Add(*proto.BaseKey, int32) (*proto.AddResponse, error)
|
||||
|
|
|
@ -72,6 +72,24 @@ func decode(method string, buf []byte) (protobuf.Message, error) {
|
|||
return decodeRPush(buf)
|
||||
case "RPushX":
|
||||
return decodeRPushX(buf)
|
||||
case "HDel":
|
||||
return decodeHDel(buf)
|
||||
case "HExists":
|
||||
return decodeHExists(buf)
|
||||
case "HGet":
|
||||
return decodeHGet(buf)
|
||||
case "HGetAll":
|
||||
return decodeHGetAll(buf)
|
||||
case "HIncrBy":
|
||||
return decodeHIncrBy(buf)
|
||||
case "HKeys":
|
||||
return decodeHKeys(buf)
|
||||
case "HLen":
|
||||
return decodeHLen(buf)
|
||||
case "HSet":
|
||||
return decodeHSet(buf)
|
||||
case "HSetX":
|
||||
return decodeHSetX(buf)
|
||||
case "Set":
|
||||
return decodeSet(buf)
|
||||
case "Get":
|
||||
|
@ -206,6 +224,87 @@ func decodeRPushX(buf []byte) (*proto.RPushXRequest, error) {
|
|||
return req, nil
|
||||
}
|
||||
|
||||
func decodeHDel(buf []byte) (*proto.HDelRequest, error) {
|
||||
req := &proto.HDelRequest{}
|
||||
err := protobuf.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func decodeHExists(buf []byte) (*proto.HExistsRequest, error) {
|
||||
req := &proto.HExistsRequest{}
|
||||
err := protobuf.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func decodeHGet(buf []byte) (*proto.HGetRequest, error) {
|
||||
req := &proto.HGetRequest{}
|
||||
err := protobuf.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func decodeHGetAll(buf []byte) (*proto.HGetAllRequest, error) {
|
||||
req := &proto.HGetAllRequest{}
|
||||
err := protobuf.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func decodeHIncrBy(buf []byte) (*proto.HIncrByRequest, error) {
|
||||
req := &proto.HIncrByRequest{}
|
||||
err := protobuf.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func decodeHKeys(buf []byte) (*proto.HKeysRequest, error) {
|
||||
req := &proto.HKeysRequest{}
|
||||
err := protobuf.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func decodeHLen(buf []byte) (*proto.HLenRequest, error) {
|
||||
req := &proto.HLenRequest{}
|
||||
err := protobuf.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func decodeHSet(buf []byte) (*proto.HSetRequest, error) {
|
||||
req := &proto.HSetRequest{}
|
||||
err := protobuf.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func decodeHSetX(buf []byte) (*proto.HSetXRequest, error) {
|
||||
req := &proto.HSetXRequest{}
|
||||
err := protobuf.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func decodeSet(buf []byte) (*proto.SetRequest, error) {
|
||||
req := &proto.SetRequest{}
|
||||
err := protobuf.Unmarshal(buf, req)
|
||||
|
|
|
@ -346,6 +346,258 @@ func (s *singleService) RPushX(
|
|||
return resp.(*proto.RPushXResponse), nil
|
||||
}
|
||||
|
||||
func (s *singleService) HDel(
|
||||
ctx context.Context,
|
||||
req *proto.HDelRequest,
|
||||
) (*proto.HDelResponse, error) {
|
||||
work := event.EventWorkFunc(func() (interface{}, error) {
|
||||
resp, err := s.dao.HDel(req.Key, req.HKeys)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.aof != nil {
|
||||
s.aof.SendRequest("HDel", req)
|
||||
}
|
||||
return resp, nil
|
||||
})
|
||||
|
||||
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
|
||||
lruEvent.InitWaitEvent()
|
||||
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
||||
s.lruProduce.Call(ctx, lruEvent)
|
||||
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
||||
s.lruProduce.Recovery(lruEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.(*proto.HDelResponse), nil
|
||||
}
|
||||
|
||||
func (s *singleService) HExists(
|
||||
ctx context.Context,
|
||||
req *proto.HExistsRequest,
|
||||
) (*proto.HExistsResponse, error) {
|
||||
work := event.EventWorkFunc(func() (interface{}, error) {
|
||||
resp, err := s.dao.HExists(req.Key, req.HKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.aof != nil {
|
||||
s.aof.SendRequest("HExists", req)
|
||||
}
|
||||
return resp, nil
|
||||
})
|
||||
|
||||
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
|
||||
lruEvent.InitWaitEvent()
|
||||
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
||||
s.lruProduce.Call(ctx, lruEvent)
|
||||
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
||||
s.lruProduce.Recovery(lruEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.(*proto.HExistsResponse), nil
|
||||
}
|
||||
|
||||
func (s *singleService) HGet(
|
||||
ctx context.Context,
|
||||
req *proto.HGetRequest,
|
||||
) (*proto.HGetResponse, error) {
|
||||
work := event.EventWorkFunc(func() (interface{}, error) {
|
||||
resp, err := s.dao.HGet(req.Key, req.HKeys)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.aof != nil {
|
||||
s.aof.SendRequest("HGet", req)
|
||||
}
|
||||
return resp, nil
|
||||
})
|
||||
|
||||
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
|
||||
lruEvent.InitWaitEvent()
|
||||
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
||||
s.lruProduce.Call(ctx, lruEvent)
|
||||
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
||||
s.lruProduce.Recovery(lruEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.(*proto.HGetResponse), nil
|
||||
}
|
||||
|
||||
func (s *singleService) HGetAll(
|
||||
ctx context.Context,
|
||||
req *proto.HGetAllRequest,
|
||||
) (*proto.HGetAllResponse, error) {
|
||||
work := event.EventWorkFunc(func() (interface{}, error) {
|
||||
resp, err := s.dao.HGetAll(req.Key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.aof != nil {
|
||||
s.aof.SendRequest("HGetAll", req)
|
||||
}
|
||||
return resp, nil
|
||||
})
|
||||
|
||||
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
|
||||
lruEvent.InitWaitEvent()
|
||||
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
||||
s.lruProduce.Call(ctx, lruEvent)
|
||||
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
||||
s.lruProduce.Recovery(lruEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.(*proto.HGetAllResponse), nil
|
||||
}
|
||||
|
||||
func (s *singleService) HIncrBy(
|
||||
ctx context.Context,
|
||||
req *proto.HIncrByRequest,
|
||||
) (*proto.HIncrByResponse, error) {
|
||||
work := event.EventWorkFunc(func() (interface{}, error) {
|
||||
resp, err := s.dao.HIncrBy(req.Key, req.HKeys)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.aof != nil {
|
||||
s.aof.SendRequest("HIncrBy", req)
|
||||
}
|
||||
return resp, nil
|
||||
})
|
||||
|
||||
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
|
||||
lruEvent.InitWaitEvent()
|
||||
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
||||
s.lruProduce.Call(ctx, lruEvent)
|
||||
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
||||
s.lruProduce.Recovery(lruEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.(*proto.HIncrByResponse), nil
|
||||
}
|
||||
|
||||
func (s *singleService) HKeys(
|
||||
ctx context.Context,
|
||||
req *proto.HKeysRequest,
|
||||
) (*proto.HKeysResponse, error) {
|
||||
work := event.EventWorkFunc(func() (interface{}, error) {
|
||||
resp, err := s.dao.HKeys(req.Key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.aof != nil {
|
||||
s.aof.SendRequest("HKeys", req)
|
||||
}
|
||||
return resp, nil
|
||||
})
|
||||
|
||||
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
|
||||
lruEvent.InitWaitEvent()
|
||||
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
||||
s.lruProduce.Call(ctx, lruEvent)
|
||||
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
||||
s.lruProduce.Recovery(lruEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.(*proto.HKeysResponse), nil
|
||||
}
|
||||
|
||||
func (s *singleService) HLen(
|
||||
ctx context.Context,
|
||||
req *proto.HLenRequest,
|
||||
) (*proto.HLenResponse, error) {
|
||||
work := event.EventWorkFunc(func() (interface{}, error) {
|
||||
resp, err := s.dao.HLen(req.Key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.aof != nil {
|
||||
s.aof.SendRequest("HLen", req)
|
||||
}
|
||||
return resp, nil
|
||||
})
|
||||
|
||||
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
|
||||
lruEvent.InitWaitEvent()
|
||||
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
||||
s.lruProduce.Call(ctx, lruEvent)
|
||||
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
||||
s.lruProduce.Recovery(lruEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.(*proto.HLenResponse), nil
|
||||
}
|
||||
|
||||
func (s *singleService) HSet(
|
||||
ctx context.Context,
|
||||
req *proto.HSetRequest,
|
||||
) (*proto.HSetResponse, error) {
|
||||
work := event.EventWorkFunc(func() (interface{}, error) {
|
||||
resp, err := s.dao.HSet(req.Key, req.Items)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.aof != nil {
|
||||
s.aof.SendRequest("HSet", req)
|
||||
}
|
||||
return resp, nil
|
||||
})
|
||||
|
||||
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
|
||||
lruEvent.InitWaitEvent()
|
||||
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
||||
s.lruProduce.Call(ctx, lruEvent)
|
||||
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
||||
s.lruProduce.Recovery(lruEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.(*proto.HSetResponse), nil
|
||||
}
|
||||
|
||||
func (s *singleService) HSetX(
|
||||
ctx context.Context,
|
||||
req *proto.HSetXRequest,
|
||||
) (*proto.HSetXResponse, error) {
|
||||
work := event.EventWorkFunc(func() (interface{}, error) {
|
||||
resp, err := s.dao.HSetX(req.Key, req.Items)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.aof != nil {
|
||||
s.aof.SendRequest("HSetX", req)
|
||||
}
|
||||
return resp, nil
|
||||
})
|
||||
|
||||
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
|
||||
lruEvent.InitWaitEvent()
|
||||
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
||||
s.lruProduce.Call(ctx, lruEvent)
|
||||
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
||||
s.lruProduce.Recovery(lruEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.(*proto.HSetXResponse), nil
|
||||
}
|
||||
|
||||
func (s *singleService) Set(
|
||||
ctx context.Context,
|
||||
req *proto.SetRequest,
|
||||
|
|
Loading…
Reference in New Issue