From f96e12a8b34784097d4c18f2c4e830b44b78f10b Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Wed, 15 Jun 2022 16:50:45 +0800 Subject: [PATCH] redis replace to go_redis --- internal/msg_gateway/gate/ws_server.go | 4 ++-- internal/rpc/msg/pull_message.go | 28 +++++++++++++------------- internal/rpc/msg/send_msg.go | 6 +++--- pkg/common/db/batch_insert_chat.go | 6 +++--- pkg/common/token_verify/jwt_token.go | 6 +++--- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index 1ce05441f..54ea7138e 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -9,7 +9,7 @@ import ( "Open_IM/pkg/utils" "bytes" "encoding/gob" - "github.com/garyburd/redigo/redis" + go_redis "github.com/go-redis/redis/v8" "net/http" "sync" "time" @@ -117,7 +117,7 @@ func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int, newConn log.NewDebug(operationID, uid, platformID, "kick old conn") ws.sendKickMsg(oldConn, newConn) 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) return } diff --git a/internal/rpc/msg/pull_message.go b/internal/rpc/msg/pull_message.go index 1736baf83..22181f09b 100644 --- a/internal/rpc/msg/pull_message.go +++ b/internal/rpc/msg/pull_message.go @@ -2,7 +2,7 @@ package msg import ( "context" - "github.com/garyburd/redigo/redis" + go_redis "github.com/go-redis/redis/v8" commonDB "Open_IM/pkg/common/db" "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) //seq, err := model.GetBiggestSeqFromReceive(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 { resp.MaxSeq = uint32(maxSeq) for _, v := range in.GroupIDList { @@ -25,22 +25,22 @@ func (rpc *rpcChat) GetMaxAndMinSeq(_ context.Context, in *open_im_sdk.GetMaxAnd m[v] = x } resp.GroupMaxAndMinSeq = m - } else if err1 == redis.ErrNil { + } else if err1 == go_redis.Nil { resp.MaxSeq = 0 } else { log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err1.Error()) resp.ErrCode = 200 resp.ErrMsg = "redis get err" } - if err2 == nil { - resp.MinSeq = uint32(minSeq) - } else if err2 == redis.ErrNil { - resp.MinSeq = 0 - } else { - log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err2.Error()) - resp.ErrCode = 201 - resp.ErrMsg = "redis get err" - } + //if err2 == nil { + // resp.MinSeq = uint32(minSeq) + //} else if err2 == redis.ErrNil { + // resp.MinSeq = 0 + //} else { + // log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err2.Error()) + // resp.ErrCode = 201 + // resp.ErrMsg = "redis get err" + //} return resp, nil } 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) redisMsgList, failedSeqList, err := commonDB.DB.GetMessageListBySeq(in.UserID, in.SeqList, in.OperationID) if err != nil { - if err != redis.ErrNil { + if err != go_redis.Nil { log.Error(in.OperationID, "get message from redis exception", err.Error(), failedSeqList) } else { 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) redisMsgList, failedSeqList, err := commonDB.DB.GetMessageListBySeq(k, v.SeqList, in.OperationID) if err != nil { - if err != redis.ErrNil { + if err != go_redis.Nil { log.Error(in.OperationID, "get message from redis exception", err.Error(), failedSeqList) } else { log.Debug(in.OperationID, "get message from redis is nil", failedSeqList) diff --git a/internal/rpc/msg/send_msg.go b/internal/rpc/msg/send_msg.go index 0419458e6..fffbf6789 100644 --- a/internal/rpc/msg/send_msg.go +++ b/internal/rpc/msg/send_msg.go @@ -15,7 +15,7 @@ import ( "Open_IM/pkg/utils" "context" "errors" - "github.com/garyburd/redigo/redis" + go_redis "github.com/go-redis/redis/v8" "github.com/golang/protobuf/proto" "math/rand" "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 { conversationID := utils.GetConversationIDBySessionType(sourceID, sessionType) 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()) 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 { conversationID := utils.GetConversationIDBySessionType(sourceID, sessionType) 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()) return true } diff --git a/pkg/common/db/batch_insert_chat.go b/pkg/common/db/batch_insert_chat.go index fd037998c..c6b57201f 100644 --- a/pkg/common/db/batch_insert_chat.go +++ b/pkg/common/db/batch_insert_chat.go @@ -7,7 +7,7 @@ import ( "Open_IM/pkg/utils" "context" "errors" - "github.com/garyburd/redigo/redis" + go_redis "github.com/go-redis/redis/v8" "github.com/golang/protobuf/proto" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" @@ -112,7 +112,7 @@ func (d *DataBases) BatchInsertChat2Cache(userID string, msgList []*pbMsg.MsgDat currentMaxSeq, err := d.GetUserMaxSeq(userID) if err == nil { - } else if err == redis.ErrNil { + } else if err == go_redis.Nil { currentMaxSeq = 0 } else { return utils.Wrap(err, ""), 0 @@ -161,7 +161,7 @@ func (d *DataBases) BatchInsertChat(userID string, msgList []*pbMsg.MsgDataToMQ, currentMaxSeq, err := d.GetUserMaxSeq(userID) if err == nil { - } else if err == redis.ErrNil { + } else if err == go_redis.Nil { isInit = true currentMaxSeq = 0 } else { diff --git a/pkg/common/token_verify/jwt_token.go b/pkg/common/token_verify/jwt_token.go index f1e95bba7..aed09190f 100644 --- a/pkg/common/token_verify/jwt_token.go +++ b/pkg/common/token_verify/jwt_token.go @@ -6,7 +6,7 @@ import ( commonDB "Open_IM/pkg/common/db" "Open_IM/pkg/common/log" "Open_IM/pkg/utils" - "github.com/garyburd/redigo/redis" + go_redis "github.com/go-redis/redis/v8" "github.com/golang-jwt/jwt/v4" "time" ) @@ -39,7 +39,7 @@ func BuildClaims(uid, platform string, ttl int64) Claims { func DeleteToken(userID string, platformID int) error { 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, "") } var deleteTokenKey []string @@ -65,7 +65,7 @@ func CreateToken(userID string, platformID int) (string, int64, error) { } //remove Invalid token 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 } var deleteTokenKey []string