forked from p93542168/wheat-cache
262 lines
6.3 KiB
Go
262 lines
6.3 KiB
Go
package single
|
|
|
|
import (
|
|
context "context"
|
|
|
|
"gitee.com/timedb/wheatCache/pkg/event"
|
|
"gitee.com/timedb/wheatCache/pkg/lru"
|
|
"gitee.com/timedb/wheatCache/pkg/proto"
|
|
)
|
|
|
|
func (s *serverSingle) LIndex(
|
|
ctx context.Context,
|
|
req *proto.LIndexRequest,
|
|
) (*proto.LIndexResponse, error) {
|
|
work := event.EventWorkFunc(func() (interface{}, error) {
|
|
return s.dao.LINdex(req.Key, req.Index)
|
|
})
|
|
|
|
lruEvent := event.NewEvent(lru.OptionEventName)
|
|
lruEvent.InitWaitEvent()
|
|
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
|
s.lruProduce.Call(ctx, lruEvent)
|
|
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &proto.LIndexResponse{
|
|
Result: resp.(string),
|
|
}, nil
|
|
}
|
|
|
|
func (s *serverSingle) LLen(
|
|
ctx context.Context,
|
|
req *proto.LLenRequest,
|
|
) (*proto.LLenResponse, error) {
|
|
work := event.EventWorkFunc(func() (interface{}, error) {
|
|
return s.dao.LLen(req.Key)
|
|
})
|
|
|
|
lruEvent := event.NewEvent(lru.OptionEventName)
|
|
lruEvent.InitWaitEvent()
|
|
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
|
s.lruProduce.Call(ctx, lruEvent)
|
|
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &proto.LLenResponse{
|
|
Length: resp.(int32),
|
|
}, nil
|
|
}
|
|
|
|
func (s *serverSingle) LPop(
|
|
ctx context.Context,
|
|
request *proto.LPopRequest,
|
|
) (*proto.LPopResponse, error) {
|
|
work := event.EventWorkFunc(func() (interface{}, error) {
|
|
return s.dao.LPop(request.Key, request.Count)
|
|
})
|
|
|
|
lruEvent := event.NewEvent(lru.OptionEventName)
|
|
lruEvent.InitWaitEvent()
|
|
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
|
s.lruProduce.Call(ctx, lruEvent)
|
|
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &proto.LPopResponse{
|
|
Results: resp.([]string),
|
|
}, nil
|
|
}
|
|
|
|
func (s *serverSingle) LPush(
|
|
ctx context.Context,
|
|
req *proto.LPushRequest,
|
|
) (*proto.LPushResponse, error) {
|
|
work := event.EventWorkFunc(func() (interface{}, error) {
|
|
return nil, s.dao.LPush(req.Key, req.Values...)
|
|
})
|
|
|
|
lruEvent := event.NewEvent(lru.OptionEventName)
|
|
lruEvent.InitWaitEvent()
|
|
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
|
s.lruProduce.Call(ctx, lruEvent)
|
|
_, err := lruEvent.StartWaitEvent(s.timeOut)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &proto.LPushResponse{}, nil
|
|
}
|
|
|
|
func (s *serverSingle) LPushX(
|
|
ctx context.Context,
|
|
req *proto.LPushXRequest,
|
|
) (*proto.LPushXResponse, error) {
|
|
work := event.EventWorkFunc(func() (interface{}, error) {
|
|
return nil, s.dao.LPush(req.Key, req.Values...)
|
|
})
|
|
|
|
lruEvent := event.NewEvent(lru.OptionEventName)
|
|
lruEvent.InitWaitEvent()
|
|
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
|
s.lruProduce.Call(ctx, lruEvent)
|
|
_, err := lruEvent.StartWaitEvent(s.timeOut)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &proto.LPushXResponse{}, nil
|
|
}
|
|
|
|
func (s *serverSingle) LRange(
|
|
ctx context.Context,
|
|
req *proto.LRangeRequest,
|
|
) (*proto.LRangeResponse, error) {
|
|
work := event.EventWorkFunc(func() (interface{}, error) {
|
|
return s.dao.LRange(req.Key, req.Start, req.End)
|
|
})
|
|
|
|
lruEvent := event.NewEvent(lru.OptionEventName)
|
|
lruEvent.InitWaitEvent()
|
|
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
|
s.lruProduce.Call(ctx, lruEvent)
|
|
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &proto.LRangeResponse{
|
|
Values: resp.([]string),
|
|
}, nil
|
|
}
|
|
|
|
func (s *serverSingle) LRem(
|
|
ctx context.Context,
|
|
req *proto.LRemRequest,
|
|
) (*proto.LRemResponse, error) {
|
|
work := event.EventWorkFunc(func() (interface{}, error) {
|
|
return s.dao.LRemove(req.Key, req.Count, req.Value)
|
|
})
|
|
|
|
lruEvent := event.NewEvent(lru.OptionEventName)
|
|
lruEvent.InitWaitEvent()
|
|
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
|
s.lruProduce.Call(ctx, lruEvent)
|
|
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &proto.LRemResponse{
|
|
Count: resp.(int32),
|
|
}, nil
|
|
}
|
|
|
|
func (s *serverSingle) LSet(
|
|
ctx context.Context,
|
|
req *proto.LSetRequest,
|
|
) (*proto.LSetResponse, error) {
|
|
work := event.EventWorkFunc(func() (interface{}, error) {
|
|
return nil, s.dao.LSet(req.Key, req.Index, req.Value)
|
|
})
|
|
|
|
lruEvent := event.NewEvent(lru.OptionEventName)
|
|
lruEvent.InitWaitEvent()
|
|
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
|
s.lruProduce.Call(ctx, lruEvent)
|
|
_, err := lruEvent.StartWaitEvent(s.timeOut)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &proto.LSetResponse{}, nil
|
|
}
|
|
|
|
func (s *serverSingle) RPop(
|
|
ctx context.Context,
|
|
req *proto.RPopRequest,
|
|
) (*proto.RPopResponse, error) {
|
|
work := event.EventWorkFunc(func() (interface{}, error) {
|
|
return s.dao.RPop(req.Key, req.Count)
|
|
})
|
|
|
|
lruEvent := event.NewEvent(lru.OptionEventName)
|
|
lruEvent.InitWaitEvent()
|
|
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
|
s.lruProduce.Call(ctx, lruEvent)
|
|
resp, err := lruEvent.StartWaitEvent(s.timeOut)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &proto.RPopResponse{
|
|
Result: resp.([]string),
|
|
}, nil
|
|
}
|
|
|
|
func (s *serverSingle) LTrim(
|
|
ctx context.Context,
|
|
req *proto.LTrimRequest,
|
|
) (*proto.LTrimResponse, error) {
|
|
work := event.EventWorkFunc(func() (interface{}, error) {
|
|
return nil, s.dao.LTrim(req.Key, req.Start, req.End)
|
|
})
|
|
|
|
lruEvent := event.NewEvent(lru.OptionEventName)
|
|
lruEvent.InitWaitEvent()
|
|
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
|
s.lruProduce.Call(ctx, lruEvent)
|
|
_, err := lruEvent.StartWaitEvent(s.timeOut)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &proto.LTrimResponse{}, nil
|
|
}
|
|
|
|
func (s *serverSingle) RPush(
|
|
ctx context.Context,
|
|
req *proto.RPushRequest,
|
|
) (*proto.RPushResponse, error) {
|
|
work := event.EventWorkFunc(func() (interface{}, error) {
|
|
return nil, s.dao.RPush(req.Key, req.Values...)
|
|
})
|
|
|
|
lruEvent := event.NewEvent(lru.OptionEventName)
|
|
lruEvent.InitWaitEvent()
|
|
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
|
s.lruProduce.Call(ctx, lruEvent)
|
|
_, err := lruEvent.StartWaitEvent(s.timeOut)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &proto.RPushResponse{}, nil
|
|
}
|
|
|
|
func (s *serverSingle) RPushX(
|
|
ctx context.Context,
|
|
req *proto.RPushXRequest,
|
|
) (*proto.RPushXResponse, error) {
|
|
work := event.EventWorkFunc(func() (interface{}, error) {
|
|
return nil, s.dao.RPushX(req.Key, req.Values...)
|
|
})
|
|
|
|
lruEvent := event.NewEvent(lru.OptionEventName)
|
|
lruEvent.InitWaitEvent()
|
|
lruEvent.SetValue(lru.WorkFuncEventKey, work)
|
|
s.lruProduce.Call(ctx, lruEvent)
|
|
_, err := lruEvent.StartWaitEvent(s.timeOut)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &proto.RPushXResponse{}, nil
|
|
}
|