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
a5740bdb
authored
Nov 18, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
2cebb28a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
12 deletions
controller/sku_controller.go
doc/test/r2.go
pkg/gredis/redis.go
service/service_zy.go
controller/sku_controller.go
View file @
a5740bdb
...
...
@@ -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
)
...
...
doc/test/r2.go
View file @
a5740bdb
...
...
@@ -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 {
...
...
pkg/gredis/redis.go
View file @
a5740bdb
...
...
@@ -74,10 +74,28 @@ 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
)
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
)
...
...
@@ -89,12 +107,12 @@ func Hmget(redisCon string, hkey string, targetIds []string) map[string]string {
fmt
.
Println
(
err1
)
}
for
k
,
goodsInfo
:=
range
reply
{
skuArr
[
targetIds
[
k
]]
=
goodsInfo
}
//fmt.Println(skuArr,e
rr)
//fmt.Println(skuA
rr)
return
skuArr
}
}
/*
批量或者单个查询redis数据,统一返回map[string]string
...
...
service/service_zy.go
View file @
a5740bdb
...
...
@@ -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
)
}
//拼接梯度价格
...
...
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