chore(service): update service

This commit is contained in:
bandl 2021-11-01 23:55:12 +08:00
parent 3b61f55fe3
commit 72add38cee
2 changed files with 138 additions and 23 deletions

View File

@ -15,7 +15,12 @@ func (s *singleService) LIndex(
req *proto.LIndexRequest, req *proto.LIndexRequest,
) (*proto.LIndexResponse, error) { ) (*proto.LIndexResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LIndex(req.Key, req.Index) resp, err := s.dao.LIndex(req.Key, req.Index)
if err != nil {
return nil, err
}
s.aof.SendRequest("LIndex", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -36,7 +41,12 @@ func (s *singleService) LLen(
req *proto.LLenRequest, req *proto.LLenRequest,
) (*proto.LLenResponse, error) { ) (*proto.LLenResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LLen(req.Key) resp, err := s.dao.LLen(req.Key)
if err != nil {
return nil, err
}
s.aof.SendRequest("LLen", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -57,7 +67,12 @@ func (s *singleService) LPop(
req *proto.LPopRequest, req *proto.LPopRequest,
) (*proto.LPopResponse, error) { ) (*proto.LPopResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LPop(req.Key, req.Count) resp, err := s.dao.LPop(req.Key, req.Count)
if err != nil {
return nil, err
}
s.aof.SendRequest("LPop", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -78,7 +93,12 @@ func (s *singleService) LPush(
req *proto.LPushRequest, req *proto.LPushRequest,
) (*proto.LPushResponse, error) { ) (*proto.LPushResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LPush(req.Key, req.Values) resp, err := s.dao.LPush(req.Key, req.Values)
if err != nil {
return nil, err
}
s.aof.SendRequest("LPush", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -99,7 +119,12 @@ func (s *singleService) LPushX(
req *proto.LPushXRequest, req *proto.LPushXRequest,
) (*proto.LPushXResponse, error) { ) (*proto.LPushXResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LPushX(req.Key, req.Values) resp, err := s.dao.LPushX(req.Key, req.Values)
if err != nil {
return nil, err
}
s.aof.SendRequest("LPushX", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -120,7 +145,12 @@ func (s *singleService) LRange(
req *proto.LRangeRequest, req *proto.LRangeRequest,
) (*proto.LRangeResponse, error) { ) (*proto.LRangeResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LRange(req.Key, req.Start, req.End) resp, err := s.dao.LRange(req.Key, req.Start, req.End)
if err != nil {
return nil, err
}
s.aof.SendRequest("LRange", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -141,7 +171,12 @@ func (s *singleService) LRem(
req *proto.LRemRequest, req *proto.LRemRequest,
) (*proto.LRemResponse, error) { ) (*proto.LRemResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LRem(req.Key, req.Count, req.Value) resp, err := s.dao.LRem(req.Key, req.Count, req.Value)
if err != nil {
return nil, err
}
s.aof.SendRequest("LRem", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -162,7 +197,12 @@ func (s *singleService) LSet(
req *proto.LSetRequest, req *proto.LSetRequest,
) (*proto.LSetResponse, error) { ) (*proto.LSetResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LSet(req.Key, req.Index, req.Value) resp, err := s.dao.LSet(req.Key, req.Index, req.Value)
if err != nil {
return nil, err
}
s.aof.SendRequest("LSet", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -183,7 +223,12 @@ func (s *singleService) RPop(
req *proto.RPopRequest, req *proto.RPopRequest,
) (*proto.RPopResponse, error) { ) (*proto.RPopResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.RPop(req.Key, req.Count) resp, err := s.dao.RPop(req.Key, req.Count)
if err != nil {
return nil, err
}
s.aof.SendRequest("RPop", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -204,7 +249,12 @@ func (s *singleService) LTrim(
req *proto.LTrimRequest, req *proto.LTrimRequest,
) (*proto.LTrimResponse, error) { ) (*proto.LTrimResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LTrim(req.Key, req.Start, req.End) resp, err := s.dao.LTrim(req.Key, req.Start, req.End)
if err != nil {
return nil, err
}
s.aof.SendRequest("LTrim", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -225,7 +275,12 @@ func (s *singleService) RPush(
req *proto.RPushRequest, req *proto.RPushRequest,
) (*proto.RPushResponse, error) { ) (*proto.RPushResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.RPush(req.Key, req.Values) resp, err := s.dao.RPush(req.Key, req.Values)
if err != nil {
return nil, err
}
s.aof.SendRequest("RPush", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -246,7 +301,12 @@ func (s *singleService) RPushX(
req *proto.RPushXRequest, req *proto.RPushXRequest,
) (*proto.RPushXResponse, error) { ) (*proto.RPushXResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.RPushX(req.Key, req.Values) resp, err := s.dao.RPushX(req.Key, req.Values)
if err != nil {
return nil, err
}
s.aof.SendRequest("RPushX", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -267,7 +327,12 @@ func (s *singleService) Set(
req *proto.SetRequest, req *proto.SetRequest,
) (*proto.SetResponse, error) { ) (*proto.SetResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.Set(req.Key, req.Val) resp, err := s.dao.Set(req.Key, req.Val)
if err != nil {
return nil, err
}
s.aof.SendRequest("Set", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -288,7 +353,12 @@ func (s *singleService) Get(
req *proto.GetRequest, req *proto.GetRequest,
) (*proto.GetResponse, error) { ) (*proto.GetResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.Get(req.Key) resp, err := s.dao.Get(req.Key)
if err != nil {
return nil, err
}
s.aof.SendRequest("Get", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -309,7 +379,12 @@ func (s *singleService) Add(
req *proto.AddRequest, req *proto.AddRequest,
) (*proto.AddResponse, error) { ) (*proto.AddResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.Add(req.Key, req.Renewal) resp, err := s.dao.Add(req.Key, req.Renewal)
if err != nil {
return nil, err
}
s.aof.SendRequest("Add", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -330,7 +405,12 @@ func (s *singleService) Reduce(
req *proto.ReduceRequest, req *proto.ReduceRequest,
) (*proto.ReduceResponse, error) { ) (*proto.ReduceResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.Reduce(req.Key, req.Renewal) resp, err := s.dao.Reduce(req.Key, req.Renewal)
if err != nil {
return nil, err
}
s.aof.SendRequest("Reduce", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -351,7 +431,12 @@ func (s *singleService) Setnx(
req *proto.SetnxRequest, req *proto.SetnxRequest,
) (*proto.SetnxResponse, error) { ) (*proto.SetnxResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.Setnx(req.Key, req.Val) resp, err := s.dao.Setnx(req.Key, req.Val)
if err != nil {
return nil, err
}
s.aof.SendRequest("Setnx", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -372,7 +457,12 @@ func (s *singleService) SetBit(
req *proto.SetBitRequest, req *proto.SetBitRequest,
) (*proto.SetBitResponse, error) { ) (*proto.SetBitResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.SetBit(req.Key, req.Val, req.Offer) resp, err := s.dao.SetBit(req.Key, req.Val, req.Offer)
if err != nil {
return nil, err
}
s.aof.SendRequest("SetBit", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -393,7 +483,12 @@ func (s *singleService) GetBit(
req *proto.GetBitRequest, req *proto.GetBitRequest,
) (*proto.GetBitResponse, error) { ) (*proto.GetBitResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.GetBit(req.Key, req.Offer) resp, err := s.dao.GetBit(req.Key, req.Offer)
if err != nil {
return nil, err
}
s.aof.SendRequest("GetBit", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -414,7 +509,12 @@ func (s *singleService) GetRange(
req *proto.GetRangeRequest, req *proto.GetRangeRequest,
) (*proto.GetRangeResponse, error) { ) (*proto.GetRangeResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.GetRange(req.Key, req.Start, req.End) resp, err := s.dao.GetRange(req.Key, req.Start, req.End)
if err != nil {
return nil, err
}
s.aof.SendRequest("GetRange", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -435,7 +535,12 @@ func (s *singleService) GetSet(
req *proto.GetSetRequest, req *proto.GetSetRequest,
) (*proto.GetSetResponse, error) { ) (*proto.GetSetResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.GetSet(req.Key, req.Val) resp, err := s.dao.GetSet(req.Key, req.Val)
if err != nil {
return nil, err
}
s.aof.SendRequest("GetSet", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)
@ -456,7 +561,12 @@ func (s *singleService) StrLen(
req *proto.StrLenRequest, req *proto.StrLenRequest,
) (*proto.StrLenResponse, error) { ) (*proto.StrLenResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.StrLen(req.Key) resp, err := s.dao.StrLen(req.Key)
if err != nil {
return nil, err
}
s.aof.SendRequest("StrLen", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)

View File

@ -16,7 +16,12 @@ func (s *singleService) {{key.method}}(
req *proto.{{key.method}}Request, req *proto.{{key.method}}Request,
) (*proto.{{key.method}}Response, error) { ) (*proto.{{key.method}}Response, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.{{key.method}}({% for opt in key.option %}req.{{opt[0]}}, {% endfor %}) resp, err := s.dao.{{key.method}}({% for opt in key.option %}req.{{opt[0]}}, {% endfor %})
if err != nil{
return nil, err
}
s.aof.SendRequest("{{key.method}}", req)
return resp, nil
}) })
lruEvent := s.lruProduce.NewEvent(lru.OptionEventName) lruEvent := s.lruProduce.NewEvent(lru.OptionEventName)