mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-23 09:50:27 +08:00
redis replace to go_redis
This commit is contained in:
parent
eef47017a3
commit
f96e12a8b3
@ -9,7 +9,7 @@ import (
|
|||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"github.com/garyburd/redigo/redis"
|
go_redis "github.com/go-redis/redis/v8"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -117,7 +117,7 @@ func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int, newConn
|
|||||||
log.NewDebug(operationID, uid, platformID, "kick old conn")
|
log.NewDebug(operationID, uid, platformID, "kick old conn")
|
||||||
ws.sendKickMsg(oldConn, newConn)
|
ws.sendKickMsg(oldConn, newConn)
|
||||||
m, err := db.DB.GetTokenMapByUidPid(uid, constant.PlatformIDToName(platformID))
|
m, err := db.DB.GetTokenMapByUidPid(uid, constant.PlatformIDToName(platformID))
|
||||||
if err != nil && err != redis.ErrNil {
|
if err != nil && err != go_redis.Nil {
|
||||||
log.NewError(operationID, "get token from redis err", err.Error(), uid)
|
log.NewError(operationID, "get token from redis err", err.Error(), uid)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package msg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/garyburd/redigo/redis"
|
go_redis "github.com/go-redis/redis/v8"
|
||||||
|
|
||||||
commonDB "Open_IM/pkg/common/db"
|
commonDB "Open_IM/pkg/common/db"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
@ -15,7 +15,7 @@ func (rpc *rpcChat) GetMaxAndMinSeq(_ context.Context, in *open_im_sdk.GetMaxAnd
|
|||||||
m := make(map[string]*open_im_sdk.MaxAndMinSeq)
|
m := make(map[string]*open_im_sdk.MaxAndMinSeq)
|
||||||
//seq, err := model.GetBiggestSeqFromReceive(in.UserID)
|
//seq, err := model.GetBiggestSeqFromReceive(in.UserID)
|
||||||
maxSeq, err1 := commonDB.DB.GetUserMaxSeq(in.UserID)
|
maxSeq, err1 := commonDB.DB.GetUserMaxSeq(in.UserID)
|
||||||
minSeq, err2 := commonDB.DB.GetUserMinSeq(in.UserID)
|
//minSeq, err2 := commonDB.DB.GetUserMinSeq(in.UserID)
|
||||||
if err1 == nil {
|
if err1 == nil {
|
||||||
resp.MaxSeq = uint32(maxSeq)
|
resp.MaxSeq = uint32(maxSeq)
|
||||||
for _, v := range in.GroupIDList {
|
for _, v := range in.GroupIDList {
|
||||||
@ -25,22 +25,22 @@ func (rpc *rpcChat) GetMaxAndMinSeq(_ context.Context, in *open_im_sdk.GetMaxAnd
|
|||||||
m[v] = x
|
m[v] = x
|
||||||
}
|
}
|
||||||
resp.GroupMaxAndMinSeq = m
|
resp.GroupMaxAndMinSeq = m
|
||||||
} else if err1 == redis.ErrNil {
|
} else if err1 == go_redis.Nil {
|
||||||
resp.MaxSeq = 0
|
resp.MaxSeq = 0
|
||||||
} else {
|
} else {
|
||||||
log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err1.Error())
|
log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err1.Error())
|
||||||
resp.ErrCode = 200
|
resp.ErrCode = 200
|
||||||
resp.ErrMsg = "redis get err"
|
resp.ErrMsg = "redis get err"
|
||||||
}
|
}
|
||||||
if err2 == nil {
|
//if err2 == nil {
|
||||||
resp.MinSeq = uint32(minSeq)
|
// resp.MinSeq = uint32(minSeq)
|
||||||
} else if err2 == redis.ErrNil {
|
//} else if err2 == redis.ErrNil {
|
||||||
resp.MinSeq = 0
|
// resp.MinSeq = 0
|
||||||
} else {
|
//} else {
|
||||||
log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err2.Error())
|
// log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err2.Error())
|
||||||
resp.ErrCode = 201
|
// resp.ErrCode = 201
|
||||||
resp.ErrMsg = "redis get err"
|
// resp.ErrMsg = "redis get err"
|
||||||
}
|
//}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *open_im_sdk.PullMessageBySeqListReq) (*open_im_sdk.PullMessageBySeqListResp, error) {
|
func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *open_im_sdk.PullMessageBySeqListReq) (*open_im_sdk.PullMessageBySeqListResp, error) {
|
||||||
@ -50,7 +50,7 @@ func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *open_im_sdk.Pull
|
|||||||
//msgList, err := commonDB.DB.GetMsgBySeqList(in.UserID, in.SeqList, in.OperationID)
|
//msgList, err := commonDB.DB.GetMsgBySeqList(in.UserID, in.SeqList, in.OperationID)
|
||||||
redisMsgList, failedSeqList, err := commonDB.DB.GetMessageListBySeq(in.UserID, in.SeqList, in.OperationID)
|
redisMsgList, failedSeqList, err := commonDB.DB.GetMessageListBySeq(in.UserID, in.SeqList, in.OperationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != redis.ErrNil {
|
if err != go_redis.Nil {
|
||||||
log.Error(in.OperationID, "get message from redis exception", err.Error(), failedSeqList)
|
log.Error(in.OperationID, "get message from redis exception", err.Error(), failedSeqList)
|
||||||
} else {
|
} else {
|
||||||
log.Debug(in.OperationID, "get message from redis is nil", failedSeqList)
|
log.Debug(in.OperationID, "get message from redis is nil", failedSeqList)
|
||||||
@ -72,7 +72,7 @@ func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *open_im_sdk.Pull
|
|||||||
x := new(open_im_sdk.MsgDataList)
|
x := new(open_im_sdk.MsgDataList)
|
||||||
redisMsgList, failedSeqList, err := commonDB.DB.GetMessageListBySeq(k, v.SeqList, in.OperationID)
|
redisMsgList, failedSeqList, err := commonDB.DB.GetMessageListBySeq(k, v.SeqList, in.OperationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != redis.ErrNil {
|
if err != go_redis.Nil {
|
||||||
log.Error(in.OperationID, "get message from redis exception", err.Error(), failedSeqList)
|
log.Error(in.OperationID, "get message from redis exception", err.Error(), failedSeqList)
|
||||||
} else {
|
} else {
|
||||||
log.Debug(in.OperationID, "get message from redis is nil", failedSeqList)
|
log.Debug(in.OperationID, "get message from redis is nil", failedSeqList)
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/garyburd/redigo/redis"
|
go_redis "github.com/go-redis/redis/v8"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -464,7 +464,7 @@ func returnMsg(replay *pbChat.SendMsgResp, pb *pbChat.SendMsgReq, errCode int32,
|
|||||||
func modifyMessageByUserMessageReceiveOpt(userID, sourceID string, sessionType int, pb *pbChat.SendMsgReq) bool {
|
func modifyMessageByUserMessageReceiveOpt(userID, sourceID string, sessionType int, pb *pbChat.SendMsgReq) bool {
|
||||||
conversationID := utils.GetConversationIDBySessionType(sourceID, sessionType)
|
conversationID := utils.GetConversationIDBySessionType(sourceID, sessionType)
|
||||||
opt, err := db.DB.GetSingleConversationRecvMsgOpt(userID, conversationID)
|
opt, err := db.DB.GetSingleConversationRecvMsgOpt(userID, conversationID)
|
||||||
if err != nil && err != redis.ErrNil {
|
if err != nil && err != go_redis.Nil {
|
||||||
log.NewError(pb.OperationID, "GetSingleConversationMsgOpt from redis err", conversationID, pb.String(), err.Error())
|
log.NewError(pb.OperationID, "GetSingleConversationMsgOpt from redis err", conversationID, pb.String(), err.Error())
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -487,7 +487,7 @@ func modifyMessageByUserMessageReceiveOpt(userID, sourceID string, sessionType i
|
|||||||
func modifyMessageByUserMessageReceiveOptoptimization(userID, sourceID string, sessionType int, operationID string, options *map[string]bool) bool {
|
func modifyMessageByUserMessageReceiveOptoptimization(userID, sourceID string, sessionType int, operationID string, options *map[string]bool) bool {
|
||||||
conversationID := utils.GetConversationIDBySessionType(sourceID, sessionType)
|
conversationID := utils.GetConversationIDBySessionType(sourceID, sessionType)
|
||||||
opt, err := db.DB.GetSingleConversationRecvMsgOpt(userID, conversationID)
|
opt, err := db.DB.GetSingleConversationRecvMsgOpt(userID, conversationID)
|
||||||
if err != nil && err != redis.ErrNil {
|
if err != nil && err != go_redis.Nil {
|
||||||
log.NewError(operationID, "GetSingleConversationMsgOpt from redis err", userID, conversationID, err.Error())
|
log.NewError(operationID, "GetSingleConversationMsgOpt from redis err", userID, conversationID, err.Error())
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/garyburd/redigo/redis"
|
go_redis "github.com/go-redis/redis/v8"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
@ -112,7 +112,7 @@ func (d *DataBases) BatchInsertChat2Cache(userID string, msgList []*pbMsg.MsgDat
|
|||||||
currentMaxSeq, err := d.GetUserMaxSeq(userID)
|
currentMaxSeq, err := d.GetUserMaxSeq(userID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
||||||
} else if err == redis.ErrNil {
|
} else if err == go_redis.Nil {
|
||||||
currentMaxSeq = 0
|
currentMaxSeq = 0
|
||||||
} else {
|
} else {
|
||||||
return utils.Wrap(err, ""), 0
|
return utils.Wrap(err, ""), 0
|
||||||
@ -161,7 +161,7 @@ func (d *DataBases) BatchInsertChat(userID string, msgList []*pbMsg.MsgDataToMQ,
|
|||||||
currentMaxSeq, err := d.GetUserMaxSeq(userID)
|
currentMaxSeq, err := d.GetUserMaxSeq(userID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
||||||
} else if err == redis.ErrNil {
|
} else if err == go_redis.Nil {
|
||||||
isInit = true
|
isInit = true
|
||||||
currentMaxSeq = 0
|
currentMaxSeq = 0
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
commonDB "Open_IM/pkg/common/db"
|
commonDB "Open_IM/pkg/common/db"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"github.com/garyburd/redigo/redis"
|
go_redis "github.com/go-redis/redis/v8"
|
||||||
"github.com/golang-jwt/jwt/v4"
|
"github.com/golang-jwt/jwt/v4"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -39,7 +39,7 @@ func BuildClaims(uid, platform string, ttl int64) Claims {
|
|||||||
|
|
||||||
func DeleteToken(userID string, platformID int) error {
|
func DeleteToken(userID string, platformID int) error {
|
||||||
m, err := commonDB.DB.GetTokenMapByUidPid(userID, constant.PlatformIDToName(platformID))
|
m, err := commonDB.DB.GetTokenMapByUidPid(userID, constant.PlatformIDToName(platformID))
|
||||||
if err != nil && err != redis.ErrNil {
|
if err != nil && err != go_redis.Nil {
|
||||||
return utils.Wrap(err, "")
|
return utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
var deleteTokenKey []string
|
var deleteTokenKey []string
|
||||||
@ -65,7 +65,7 @@ func CreateToken(userID string, platformID int) (string, int64, error) {
|
|||||||
}
|
}
|
||||||
//remove Invalid token
|
//remove Invalid token
|
||||||
m, err := commonDB.DB.GetTokenMapByUidPid(userID, constant.PlatformIDToName(platformID))
|
m, err := commonDB.DB.GetTokenMapByUidPid(userID, constant.PlatformIDToName(platformID))
|
||||||
if err != nil && err != redis.ErrNil {
|
if err != nil && err != go_redis.Nil {
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
}
|
}
|
||||||
var deleteTokenKey []string
|
var deleteTokenKey []string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user