|
|
package common
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
|
"strings"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
|
|
)
|
|
|
|
|
|
type CommonGetClearCacheLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
}
|
|
|
|
|
|
func NewCommonGetClearCacheLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommonGetClearCacheLogic {
|
|
|
return &CommonGetClearCacheLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l *CommonGetClearCacheLogic) CommonGetClearCache() error {
|
|
|
var (
|
|
|
appName = l.svcCtx.Config.Name
|
|
|
success int
|
|
|
)
|
|
|
if strings.TrimSpace(appName) == "" {
|
|
|
return nil
|
|
|
}
|
|
|
keyPattern := fmt.Sprintf("%s*", appName)
|
|
|
list, err := l.svcCtx.Redis.Keys(keyPattern)
|
|
|
if err != nil {
|
|
|
return xerr.NewErrMsg(err.Error())
|
|
|
}
|
|
|
for _, key := range list {
|
|
|
if _, err = l.svcCtx.Redis.Del(key); err == nil {
|
|
|
success++
|
|
|
}
|
|
|
}
|
|
|
logx.Infof("清理缓存:%d/%d", success, len(list))
|
|
|
return nil
|
|
|
} |
...
|
...
|
|