|
|
|
@ -9,6 +9,7 @@ import (
|
|
|
|
|
"dsBaseRpc/Utils/RedisUtil"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/go-redis/redis/v7"
|
|
|
|
|
"github.com/xormplus/builder"
|
|
|
|
|
"reflect"
|
|
|
|
|
"strconv"
|
|
|
|
@ -123,15 +124,23 @@ func batchWriteRedis(list []map[string]interface{}, m Selector) {
|
|
|
|
|
时间:2020-02-05
|
|
|
|
|
*/
|
|
|
|
|
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 notExistsIds []string
|
|
|
|
|
//3、输出结果
|
|
|
|
|
for i := 0; i < len(ids); i++ {
|
|
|
|
|
r := RedisUtil.RedisClient.Exists(prefix + ids[i]).Val()
|
|
|
|
|
if r > 0 {
|
|
|
|
|
n := CommonUtil.ConvertJsonStringToMap(RedisUtil.RedisClient.Get(prefix + ids[i]).Val())
|
|
|
|
|
for i := 0; i < len(list); i++ {
|
|
|
|
|
_bean := list[i].Val()
|
|
|
|
|
if len(_bean) > 0 {
|
|
|
|
|
n := CommonUtil.ConvertJsonStringToMap(_bean)
|
|
|
|
|
//找到了加到返回值列表中去
|
|
|
|
|
existList = append(existList, n)
|
|
|
|
|
} else {
|
|
|
|
@ -152,7 +161,7 @@ func Count(baseSql string) (int32, error) {
|
|
|
|
|
baseSql = strings.ToLower(baseSql)
|
|
|
|
|
//截取去掉最后面的 limit ?
|
|
|
|
|
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
|
|
|
|
|
_, err := db.SQL(countSql).Get(&count)
|
|
|
|
|
if err != nil {
|
|
|
|
|