mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-26 03:26:57 +08:00
add global msg recv opt
This commit is contained in:
parent
1e62ddce73
commit
6f0860d954
@ -10,15 +10,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
go_redis "github.com/go-redis/redis/v8"
|
||||||
"github.com/golang/protobuf/jsonpb"
|
"github.com/golang/protobuf/jsonpb"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/garyburd/redigo/redis"
|
|
||||||
|
|
||||||
//goRedis "github.com/go-redis/redis/v8"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//func (d * DataBases)pubMessage(channel, msg string) {
|
//func (d * DataBases)pubMessage(channel, msg string) {
|
||||||
@ -27,7 +23,22 @@ import (
|
|||||||
//func (d * DataBases)pubMessage(channel, msg string) {
|
//func (d * DataBases)pubMessage(channel, msg string) {
|
||||||
// d.rdb.Publish(context.Background(),channel,msg)
|
// d.rdb.Publish(context.Background(),channel,msg)
|
||||||
//}
|
//}
|
||||||
|
func (d *DataBases) SetUserGlobalMsgRecvOpt(userID string, opt int32) error {
|
||||||
|
key := conversationReceiveMessageOpt + userID
|
||||||
|
return d.rdb.HSet(context.Background(), key, GlobalMsgRecvOpt, opt).Err()
|
||||||
|
}
|
||||||
|
func (d *DataBases) GetUserGlobalMsgRecvOpt(userID string) (int, error) {
|
||||||
|
key := conversationReceiveMessageOpt + userID
|
||||||
|
result, err := d.rdb.HGet(context.Background(), key, GlobalMsgRecvOpt).Result()
|
||||||
|
if err != nil {
|
||||||
|
if err == go_redis.Nil {
|
||||||
|
return 0, nil
|
||||||
|
} else {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return utils.StringToInt(result), err
|
||||||
|
}
|
||||||
func (d *DataBases) NewGetMessageListBySeq(userID string, seqList []uint32, operationID string) (seqMsg []*pbCommon.MsgData, failedSeqList []uint32, errResult error) {
|
func (d *DataBases) NewGetMessageListBySeq(userID string, seqList []uint32, operationID string) (seqMsg []*pbCommon.MsgData, failedSeqList []uint32, errResult error) {
|
||||||
for _, v := range seqList {
|
for _, v := range seqList {
|
||||||
//MESSAGE_CACHE:169.254.225.224_reliability1653387820_0_1
|
//MESSAGE_CACHE:169.254.225.224_reliability1653387820_0_1
|
||||||
@ -83,7 +94,7 @@ func (d *DataBases) CleanUpOneUserAllMsgFromRedis(userID string, operationID str
|
|||||||
key := messageCache + userID + "_" + "*"
|
key := messageCache + userID + "_" + "*"
|
||||||
vals, err := d.rdb.Keys(ctx, key).Result()
|
vals, err := d.rdb.Keys(ctx, key).Result()
|
||||||
log2.Debug(operationID, "vals: ", vals)
|
log2.Debug(operationID, "vals: ", vals)
|
||||||
if err == redis.ErrNil {
|
if err == go_redis.Nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -36,6 +36,7 @@ const (
|
|||||||
messageCache = "MESSAGE_CACHE:"
|
messageCache = "MESSAGE_CACHE:"
|
||||||
SignalCache = "SIGNAL_CACHE:"
|
SignalCache = "SIGNAL_CACHE:"
|
||||||
SignalListCache = "SIGNAL_LIST_CACHE:"
|
SignalListCache = "SIGNAL_LIST_CACHE:"
|
||||||
|
GlobalMsgRecvOpt = "GLOBAL_MSG_RECV_OPT"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *DataBases) Exec(cmd string, key interface{}, args ...interface{}) (interface{}, error) {
|
func (d *DataBases) Exec(cmd string, key interface{}, args ...interface{}) (interface{}, error) {
|
||||||
|
@ -87,3 +87,16 @@ func Test_NewGetMessageListBySeq(t *testing.T) {
|
|||||||
fmt.Println(seqMsg, failedSeqList)
|
fmt.Println(seqMsg, failedSeqList)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
func Test_SetUserGlobalMsgRecvOpt(t *testing.T) {
|
||||||
|
var opt int32
|
||||||
|
uid := "test_uid"
|
||||||
|
opt = 1
|
||||||
|
err := DB.SetUserGlobalMsgRecvOpt(uid, opt)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
func Test_GetUserGlobalMsgRecvOpt(t *testing.T) {
|
||||||
|
uid := "test_uid"
|
||||||
|
opt, err := DB.GetUserGlobalMsgRecvOpt(uid)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
fmt.Println("get opt", opt)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user