Commit a5740bdb by huangchengyi

1.0

parent 2cebb28a
......@@ -49,13 +49,14 @@ func Synchronization(ctx *gin.Context) {
zyGoodsId := make([]string, 0)
lyGoodsId := make([]string, 0)
for _, goods_id := range goodsIdArr {
if goods_id == "" {
continue;
}
if len(goods_id) < 19 { //自营
zyGoodsId = append(zyGoodsId, goods_id)
if len(zyGoodsId) >= goods_slice_count {
common.PrintDebugHtml(ctx, "zy增加协程:")
common.PrintDebugHtml(ctx, "zy增加协程1001:")
common.PrintDebugHtml(ctx, zyGoodsId)
wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(ctx, zyGoodsId, &GoodsRes, &wg)
zyGoodsId = zyGoodsId[:0:0]
......@@ -63,7 +64,7 @@ func Synchronization(ctx *gin.Context) {
} else { //联营
lyGoodsId = append(lyGoodsId, goods_id)
if len(lyGoodsId) >= goods_slice_count {
common.PrintDebugHtml(ctx, "ly增加协程:")
common.PrintDebugHtml(ctx, "ly增加协程1002:")
common.PrintDebugHtml(ctx, zyGoodsId)
wg.Add(1)
go lyService.LyGoodsDetail(ctx, lyGoodsId, &GoodsRes, &wg)
......@@ -73,14 +74,14 @@ func Synchronization(ctx *gin.Context) {
}
if len(zyGoodsId) > 0 {
common.PrintDebugHtml(ctx, "zy增加协程:")
common.PrintDebugHtml(ctx, "zy增加协程1003:")
common.PrintDebugHtml(ctx, zyGoodsId)
wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(ctx, zyGoodsId, &GoodsRes, &wg)
}
if len(lyGoodsId) >= 0 {
common.PrintDebugHtml(ctx, "ly增加协程:")
if len(lyGoodsId) > 0 {
common.PrintDebugHtml(ctx, "ly增加协程1004:")
common.PrintDebugHtml(ctx, zyGoodsId)
wg.Add(1)
go lyService.LyGoodsDetail(ctx, lyGoodsId, &GoodsRes, &wg)
......
......@@ -18,10 +18,10 @@ func main() {
}
defer c1.Close()
good_id := []interface{}{"spu","2160558271613306802","2160551632152235701"}
// good_id := []interface{}{"spu","2160558271613306802","2160551632152235701"}
// res1,err := c1.Do("hmget","spu","2160558271613306802","2160551632152235701")
res1,err := c1.Do("hmget","spu",good_id)
res1,err := c1.Do("hmget","spu","2160558271613306802")
reply, err := redis.Strings(res1,err)
//if err != nil {
......
......@@ -74,27 +74,45 @@ eg:
skuArr := gredis.HgetPi(&redisConn,"Self_SelfGoods",[]string{"1001","10005"})
*/
func Hmget(redisCon string, hkey string, targetIds []string) map[string]string {
if len(targetIds) == 0 {
fmt.Println("批量查询不得传入空")
return nil
}
redisConn := Conn(redisCon)
defer redisConn.Close()
skuArr := make(map[string]string, 0)
param := []interface{}{hkey}
for _, goods_id := range targetIds {
param = append(param, goods_id)
}
res1,err1 := redisConn.Do("hmget",param...)
reply, _ := redis.Strings(res1,err1)
if err1 != nil {
fmt.Println(err1)
}
if len(targetIds) == 1 {
goods_id := targetIds[0];
info, err := String(redisConn.Do("HGET", hkey, goods_id))
if err != nil {
fmt.Print("连接redis错误991:", err)
}
if info == "" {
skuArr[goods_id] = ""
} else {
skuArr[goods_id] = info
}
fmt.Println("单个查询")
return skuArr
}else{ //多个查询
param := []interface{}{hkey}
for _, goods_id := range targetIds {
param = append(param, goods_id)
}
res1,err1 := redisConn.Do("hmget",param...)
reply, _ := redis.Strings(res1,err1)
if err1 != nil {
fmt.Println(err1)
}
for k, goodsInfo := range reply {
skuArr[targetIds[k]] = goodsInfo
for k, goodsInfo := range reply {
skuArr[targetIds[k]] = goodsInfo
}
//fmt.Println(skuArr)
return skuArr
}
//fmt.Println(skuArr,err)
return skuArr
}
/*
批量或者单个查询redis数据,统一返回map[string]string
......
......@@ -43,7 +43,7 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
for goods_id,info := range skuArr {
if gjson.Get(info, "goods_name").String() == "" {
fmt.Print("报错redis 1001-----",goods_id,skuArr)
fmt.Print("zy goods_name为空-----",goods_id,skuArr)
}
//拼接梯度价格
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment