feat: en redis and logs
This commit is contained in:
@@ -11,7 +11,9 @@ import (
|
||||
"product/internal/svc"
|
||||
"product/product"
|
||||
|
||||
"pkg.local/log"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/redis"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -34,6 +36,11 @@ func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
|
||||
}
|
||||
|
||||
func (l *AddLogic) Add(in *product.AddReq) (*product.AddResp, error) {
|
||||
l.Info("zero logx 方式 ... ")
|
||||
log.Info("原始 zap 方式 ... ")
|
||||
|
||||
redis.Client.Get(l.ctx, redis.GetRedisKey("product:test"))
|
||||
|
||||
if in.GetType() == dao.ProductTypeNormal {
|
||||
if in.GetAgentPrice() == 0 || in.GetStorePrice() == 0 ||
|
||||
in.GetSalePrice() == 0 || in.GetSharePrice() == 0 ||
|
||||
@@ -56,7 +63,7 @@ func (l *AddLogic) Add(in *product.AddReq) (*product.AddResp, error) {
|
||||
Eq: map[string]string{"name": in.GetName()},
|
||||
}, &check)
|
||||
if err != nil {
|
||||
l.Errorf("check product name: %v", err)
|
||||
log.Errorf("check product name: %v", err)
|
||||
return nil, status.Error(codes.Internal, "查询失败")
|
||||
}
|
||||
if check.Id > 0 {
|
||||
@@ -150,10 +157,18 @@ func (l *AddLogic) Add(in *product.AddReq) (*product.AddResp, error) {
|
||||
return model.VerifyModel{}.Init().WithTX(tx).Create(&verify)
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorf("create product: %v", err)
|
||||
log.Errorf("create product: %v", err)
|
||||
return nil, status.Error(codes.Internal, "创建失败")
|
||||
}
|
||||
|
||||
// redis 用法示例
|
||||
key := redis.GetRedisKey("product:last_add")
|
||||
if err := redis.Client.Set(l.ctx, key, in.GetName(), time.Hour).Err(); err != nil {
|
||||
log.Errorf("redis set %s: %v", key, err)
|
||||
} else {
|
||||
log.Infof("add product success id=%d", data.Id)
|
||||
}
|
||||
|
||||
return &product.AddResp{}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user