master
huanghai 5 years ago
parent e677a7999c
commit edf16a2932

@ -9,6 +9,7 @@ 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"
@ -123,15 +124,23 @@ 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、执行管道
pipe.Exec()
//存在于缓存中的数据 //存在于缓存中的数据
var existList []map[string]interface{} var existList []map[string]interface{}
//不存在的主键有哪些 //不存在的主键有哪些
var notExistsIds []string var notExistsIds []string
//3、输出结果 //3、输出结果
for i := 0; i < len(ids); i++ { for i := 0; i < len(list); i++ {
r := RedisUtil.RedisClient.Exists(prefix + ids[i]).Val() _bean := list[i].Val()
if r > 0 { if len(_bean) > 0 {
n := CommonUtil.ConvertJsonStringToMap(RedisUtil.RedisClient.Get(prefix + ids[i]).Val()) n := CommonUtil.ConvertJsonStringToMap(_bean)
//找到了加到返回值列表中去 //找到了加到返回值列表中去
existList = append(existList, n) existList = append(existList, n)
} else { } else {
@ -152,7 +161,7 @@ func Count(baseSql string) (int32, error) {
baseSql = strings.ToLower(baseSql) baseSql = strings.ToLower(baseSql)
//截取去掉最后面的 limit ? //截取去掉最后面的 limit ?
baseSql = strings.Split(baseSql, " limit ")[0] baseSql = strings.Split(baseSql, " limit ")[0]
countSql := "SELECT Count(1) as Count from (" + baseSql + ") as t100" countSql := "select count(1) as count from (" + baseSql + ") as t100"
var count int32 var count int32
_, err := db.SQL(countSql).Get(&count) _, err := db.SQL(countSql).Get(&count)
if err != nil { if err != nil {

Loading…
Cancel
Save