Commit 5ce78307 by huangchengyi

1.0

parent f81ca555
Showing with 32 additions and 1 deletions
...@@ -106,3 +106,29 @@ func HgetPi(redisCon string,hkey string,targetIds []string) map[string]string { ...@@ -106,3 +106,29 @@ func HgetPi(redisCon string,hkey string,targetIds []string) map[string]string {
} }
return skuArr return skuArr
} }
/*
批量或者单个查询redis数据,统一返回map[string]string
@param hkey string 集合键值,如sku
@param targetIds string 查询的id 切片
eg:
redisConn := gredis.Conn("search_r")
skuArr := gredis.HgetPi(&redisConn,"Self_SelfGoods",[]string{"1001","10005"})
*/
func HgetPi2(redisCon string,hkey string,targetIds []string) map[string]string {
redisConn := Conn(redisCon)
defer redisConn.Close()
skuArr := make(map[string]string,0)
for _,goods_id := range targetIds{
info,err := String(redisConn.Do("HGET",hkey,goods_id))
fmt.Print(err)
if info == "" {
skuArr[goods_id] = ""
}else{
skuArr[goods_id] = info
}
}
return skuArr
}
package service package service
import ( import (
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/iancoleman/orderedmap" "github.com/iancoleman/orderedmap"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
...@@ -38,10 +39,14 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR ...@@ -38,10 +39,14 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
redisConn.Close(); redisConn.Close();
}() }()
skuArr := gredis.HgetPi("search_r","Self_SelfGoods",goodsIds) //批量获取商品详情 skuArr := gredis.HgetPi2("search_r","Self_SelfGoods",goodsIds) //批量获取商品详情
fmt.Print("查询redis",len(skuArr))
fast := ctx.Request.FormValue("power[fast]") fast := ctx.Request.FormValue("power[fast]")
for goods_id,info := range skuArr { for goods_id,info := range skuArr {
if gjson.Get(info, "goods_name").String() == "" {
fmt.Print("报错-----",goods_id,skuArr)
}
//拼接梯度价格 //拼接梯度价格
ladder_price_arr := gjson.Get(info,"ladder_price").Array() ladder_price_arr := gjson.Get(info,"ladder_price").Array()
......
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