Browse Source

signIn 进行限频

master
DengBiao 1 year ago
parent
commit
75814ae11f
2 changed files with 9 additions and 2 deletions
  1. +1
    -1
      config/config.go
  2. +8
    -1
      internal/logic/domain/device/device_service.go

+ 1
- 1
config/config.go View File

@@ -21,7 +21,7 @@ const (

var (
NameSpace string = "gim"
MySQL string = "root:Fnuo123com@@tcp(119.23.182.117:3306)/gim?charset=utf8&parseTime=true"
MySQL string = "root:Fnuo123com@@tcp(119.23.182.117:3306)/gim?charset=utf8&parseTime=true&loc=Local"
RedisIP string = "120.24.28.6:32572"
RedisPassword string = ""



+ 8
- 1
internal/logic/domain/device/device_service.go View File

@@ -41,9 +41,16 @@ func (*deviceService) SignIn(ctx context.Context, userId, deviceId int64, token
masterId, _ := grpclib.GetCtxMasterId(ctx)
cacheKey := fmt.Sprintf(SignInKey, masterId, utils.Int64ToStr(userId))
if db.RedisUtil.Exists(cacheKey) {
utils.FilePutContents("sign_in", utils.SerializeStr(map[string]interface{}{
"user_id": userId,
"device_id": deviceId,
"token": token,
"conn_addr": connAddr,
"client_addr": clientAddr,
}))
return errors.New("限频!!!")
} else {
err := db.RedisUtil.Set(SignInKey, "already", SignInExpire)
err := db.RedisUtil.Set(cacheKey, "already", SignInExpire)
if err != nil {
return gerrors.WrapError(err)
}


Loading…
Cancel
Save