Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5ce78307
authored
Sep 28, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
f81ca555
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletions
pkg/gredis/redis.go
service/service_zy.go
pkg/gredis/redis.go
View file @
5ce78307
...
@@ -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
}
service/service_zy.go
View file @
5ce78307
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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment