master
huanghai 5 years ago
parent b793bb7ca8
commit 60100abb68

@ -33,6 +33,13 @@ func init() {
Addr: redisHost, // Redis地址 Addr: redisHost, // Redis地址
Password: "", // Redis账号 Password: "", // Redis账号
DB: 0, // Redis库 DB: 0, // Redis库
DialTimeout: 10 * time.Second,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
PoolSize: 10,
PoolTimeout: 30 * time.Second,
IdleTimeout: time.Minute,
IdleCheckFrequency: 100 * time.Millisecond,
}) })
_, err := RedisClient.Ping().Result() _, err := RedisClient.Ping().Result()

@ -9,7 +9,6 @@ import (
"dsBaseRpc/Utils/RedisUtil" "dsBaseRpc/Utils/RedisUtil"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/go-redis/redis/v7"
"github.com/xormplus/builder" "github.com/xormplus/builder"
"reflect" "reflect"
"strconv" "strconv"
@ -124,25 +123,15 @@ func batchWriteRedis(list []map[string]interface{}, m Selector) {
2020-02-05 2020-02-05
*/ */
func batchReadRedis(ids []string, prefix string) ([]map[string]interface{}, []string) { func batchReadRedis(ids []string, prefix string) ([]map[string]interface{}, []string) {
//1、创建管道
var list []*redis.StringCmd
pipe := RedisUtil.RedisClient.Pipeline()
for i := 0; i < len(ids); i++ {
list = append(list, pipe.Get(prefix+ids[i]))
}
//2、执行管道
_, err := pipe.Exec()
if err != nil {
LogUtil.Error(ErrorConst.RedisError, err.Error())
}
//存在于缓存中的数据 //存在于缓存中的数据
var existList []map[string]interface{} var existList []map[string]interface{}
//不存在的主键有哪些 //不存在的主键有哪些
var notExistsIds []string var notExistsIds []string
//3、输出结果
for i := 0; i < len(list); i++ { //1、创建管道
_bean := list[i].Val() for i := 0; i < len(ids); i++ {
if len(_bean) > 0 { _bean, err := RedisUtil.GET(prefix + ids[i])
if err == nil {
n := CommonUtil.ConvertJsonStringToMap(_bean) n := CommonUtil.ConvertJsonStringToMap(_bean)
//找到了加到返回值列表中去 //找到了加到返回值列表中去
existList = append(existList, n) existList = append(existList, n)
@ -275,21 +264,21 @@ func pageCache(sql string) ([]map[string]interface{}, int32, error) {
2020-6-12 2020-6-12
*/ */
func GetTableColumns(tableName string) ([]map[string]interface{}, error) { func GetTableColumns(tableName string) ([]map[string]interface{}, error) {
sql := `select COLUMN_NAME from information_schema.COLUMNS where table_name = ? and table_schema = '` + ConfigUtil.MysqlDataBase + `'` sql := `select COLUMN_NAME from information_schema.COLUMNS where table_name = ? and table_schema = '` + ConfigUtil.MysqlDataBase + `'`
return db.SQL(sql,tableName).Query().List() return db.SQL(sql, tableName).Query().List()
} }
/** /**
2020-06-12 2020-06-12
*/ */
func GetTableBatchSize(tableName string)int{ func GetTableBatchSize(tableName string) int {
var maxFileds= 65535 var maxFileds = 65535
//计算每个批次的大小 //计算每个批次的大小
list,_:=GetTableColumns(tableName) list, _ := GetTableColumns(tableName)
batchSize:=maxFileds/len(list) batchSize := maxFileds / len(list)
return batchSize return batchSize
} }

Loading…
Cancel
Save