feat: local cache

This commit is contained in:
withchao 2024-01-16 15:13:49 +08:00
parent 1afdd0bcf7
commit 1c93f87e95
2 changed files with 6 additions and 71 deletions

View File

@ -204,7 +204,13 @@ func (m *msgServer) modifyMessageByUserMessageReceiveOpt(
return true, nil
}
// conversationID := utils.GetConversationIDBySessionType(conversationID, sessionType)
log.ZDebug(ctx, "GetSingleConversationRecvMsgOpt req", "userID", userID, "conversationID", conversationID)
singleOpt, err := m.Conversation.GetSingleConversationRecvMsgOpt(ctx, userID, conversationID) // todo local cache
if err == nil {
log.ZDebug(ctx, "GetSingleConversationRecvMsgOpt resp", "userID", userID, "conversationID", conversationID, "RecvMsgOpt", singleOpt)
} else {
log.ZError(ctx, "GetSingleConversationRecvMsgOpt resp", err, "userID", userID, "conversationID", conversationID, "RecvMsgOpt", singleOpt)
}
if errs.ErrRecordNotFound.Is(err) {
return true, nil
} else if err != nil {

View File

@ -1,71 +0,0 @@
package localcache
//
//import (
// "context"
// "encoding/json"
// "github.com/OpenIMSDK/tools/log"
// "github.com/dtm-labs/rockscache"
// "github.com/redis/go-redis/v9"
//)
//
//func WithRedisDeleteSubscribe(topic string, cli redis.UniversalClient) Option {
// return WithDeleteLocal(func(fn func(key ...string)) {
// if fn == nil {
// log.ZDebug(context.Background(), "WithRedisDeleteSubscribe fn is nil", "topic", topic)
// return
// }
// msg := cli.Subscribe(context.Background(), topic).Channel()
// for m := range msg {
// log.ZDebug(context.Background(), "WithRedisDeleteSubscribe delete", "topic", m.Channel, "payload", m.Payload)
// var key []string
// if err := json.Unmarshal([]byte(m.Payload), &key); err != nil {
// log.ZError(context.Background(), "WithRedisDeleteSubscribe json unmarshal error", err, "topic", topic, "payload", m.Payload)
// continue
// }
// if len(key) == 0 {
// continue
// }
// fn(key...)
// }
// })
//}
//
//func WithRedisDeletePublish(topic string, cli redis.UniversalClient) Option {
// return WithDeleteKeyBefore(func(ctx context.Context, key ...string) {
// data, err := json.Marshal(key)
// if err != nil {
// log.ZError(ctx, "json marshal error", err, "topic", topic, "key", key)
// return
// }
// if err := cli.Publish(ctx, topic, data).Err(); err != nil {
// log.ZError(ctx, "redis publish error", err, "topic", topic, "key", key)
// } else {
// log.ZDebug(ctx, "redis publish success", "topic", topic, "key", key)
// }
// })
//}
//
//func WithRedisDelete(cli redis.UniversalClient) Option {
// return WithDeleteKeyBefore(func(ctx context.Context, key ...string) {
// for _, s := range key {
// if err := cli.Del(ctx, s).Err(); err != nil {
// log.ZError(ctx, "redis delete error", err, "key", s)
// } else {
// log.ZDebug(ctx, "redis delete success", "key", s)
// }
// }
// })
//}
//
//func WithRocksCacheDelete(cli *rockscache.Client) Option {
// return WithDeleteKeyBefore(func(ctx context.Context, key ...string) {
// for _, k := range key {
// if err := cli.TagAsDeleted2(ctx, k); err != nil {
// log.ZError(ctx, "rocksdb delete error", err, "key", k)
// } else {
// log.ZDebug(ctx, "rocksdb delete success", "key", k)
// }
// }
// })
//}