You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package SysKit
import (
"dsBaseRpc/Const"
"dsBaseRpc/Utils/CommonUtil"
"dsBaseRpc/Utils/DbUtil"
"dsBaseRpc/Utils/RedisUtil"
"fmt"
"strings"
)
//操作数据库的变量
var db = DbUtil.Engine
/**
功能初始化每类人群三种的最大num值放入redis防止并发冲突
作者:黄海
时间2020-06-03
*/
func InitLoginIdIntMax() {
sql := "select ifnull(max(id_int),0) as login_id_int_max from t_sys_loginperson"
list, _ := db.SQL(sql).Query().List()
loginIdIntMax := list[0]["login_id_int_max"].(int64)
RedisUtil.SET(Const.LoginIdIntMax, CommonUtil.ConvertInt64ToString(loginIdIntMax), -1)
fmt.Println("初始化登录名的最大序列成功完成!")
}
/**
功能清理Rpc层调用生成的redis缓存一般用在重启动项目时防止因数据库修改造成缓存不一致
作者:黄海
时间2020-06-03
*/
func ClearRpcRedis() {
var redisClient = RedisUtil.RedisClient
var cursor uint64
var n int
//不能删除的前缀,统一认证在用的前缀
excludePrefix := []string{"oauth2:access", "TJoinApp"}
includePrefix := []string{"T*", "pk_*"}
//每一种需要清理的前缀
for k := range includePrefix {
// while true 一直在处理,直到没有了~
for {
var keys []string
var err error
keys, cursor, err = redisClient.Scan(cursor, includePrefix[k], 100).Result()
if err != nil {
fmt.Println(err.Error())
}
if cursor == 0 {
break
}
for i := range keys {
var found = false
for j := range excludePrefix {
if strings.HasPrefix(keys[i], excludePrefix[j]) {
found = true
break
}
}
if !found {
redisClient.Del(keys[i])
n++
}
}
}
}
fmt.Printf("发现 %d 个Redis键值已成功删除!\n", n)
}