|
|
@ -18,6 +18,7 @@ import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/OpenIMSDK/tools/mw/specialerror"
|
|
|
|
"github.com/OpenIMSDK/tools/mw/specialerror"
|
|
|
@ -44,6 +45,8 @@ type metaCache interface {
|
|
|
|
AddKeys(keys ...string)
|
|
|
|
AddKeys(keys ...string)
|
|
|
|
ClearKeys()
|
|
|
|
ClearKeys()
|
|
|
|
GetPreDelKeys() []string
|
|
|
|
GetPreDelKeys() []string
|
|
|
|
|
|
|
|
SetTopic(topic string)
|
|
|
|
|
|
|
|
SetRawRedisClient(cli redis.UniversalClient)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewMetaCacheRedis(rcClient *rockscache.Client, keys ...string) metaCache {
|
|
|
|
func NewMetaCacheRedis(rcClient *rockscache.Client, keys ...string) metaCache {
|
|
|
@ -51,10 +54,20 @@ func NewMetaCacheRedis(rcClient *rockscache.Client, keys ...string) metaCache {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type metaCacheRedis struct {
|
|
|
|
type metaCacheRedis struct {
|
|
|
|
|
|
|
|
topic string
|
|
|
|
rcClient *rockscache.Client
|
|
|
|
rcClient *rockscache.Client
|
|
|
|
keys []string
|
|
|
|
keys []string
|
|
|
|
maxRetryTimes int
|
|
|
|
maxRetryTimes int
|
|
|
|
retryInterval time.Duration
|
|
|
|
retryInterval time.Duration
|
|
|
|
|
|
|
|
redisClient redis.UniversalClient
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *metaCacheRedis) SetTopic(topic string) {
|
|
|
|
|
|
|
|
m.topic = topic
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *metaCacheRedis) SetRawRedisClient(cli redis.UniversalClient) {
|
|
|
|
|
|
|
|
m.redisClient = cli
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *metaCacheRedis) ExecDel(ctx context.Context, distinct ...bool) error {
|
|
|
|
func (m *metaCacheRedis) ExecDel(ctx context.Context, distinct ...bool) error {
|
|
|
@ -72,31 +85,18 @@ func (m *metaCacheRedis) ExecDel(ctx context.Context, distinct ...bool) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//retryTimes := 0
|
|
|
|
if m.topic != "" && m.redisClient != nil {
|
|
|
|
//for {
|
|
|
|
data, err := json.Marshal(m.keys)
|
|
|
|
// m.rcClient.TagAsDeleted()
|
|
|
|
if err != nil {
|
|
|
|
// if err := m.rcClient.TagAsDeletedBatch2(ctx, []string{key}); err != nil {
|
|
|
|
log.ZError(ctx, "keys json marshal failed", err, "topic", m.topic, "keys", m.keys)
|
|
|
|
// if retryTimes >= m.maxRetryTimes {
|
|
|
|
} else {
|
|
|
|
// err = errs.ErrInternalServer.Wrap(
|
|
|
|
if err := m.redisClient.Publish(ctx, m.topic, string(data)).Err(); err != nil {
|
|
|
|
// fmt.Sprintf(
|
|
|
|
log.ZError(ctx, "redis publish cache delete error", err, "topic", m.topic, "keys", m.keys)
|
|
|
|
// "delete cache error: %v, keys: %v, retry times %d, please check redis server",
|
|
|
|
}
|
|
|
|
// err,
|
|
|
|
}
|
|
|
|
// key,
|
|
|
|
|
|
|
|
// retryTimes,
|
|
|
|
|
|
|
|
// ),
|
|
|
|
|
|
|
|
// )
|
|
|
|
|
|
|
|
// log.ZWarn(ctx, "delete cache failed, please handle keys", err, "keys", key)
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// retryTimes++
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// break
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|