Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_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
ccfbc0bc
authored
Jul 03, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
9c68f844
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
107 additions
and
29 deletions
cmd/test1.go
conf/redis_key.ini
model/ly.go
pkg/gredis/redis.go
service/common_ly_service.go
cmd/test1.go
View file @
ccfbc0bc
...
@@ -2,10 +2,8 @@ package main
...
@@ -2,10 +2,8 @@ package main
import
(
import
(
"flag"
"flag"
"fmt"
"os"
"os"
"search_server/boot"
"search_server/boot"
"search_server/pkg/gredis"
"search_server/service"
"search_server/service"
)
)
...
@@ -19,11 +17,12 @@ func main() {
...
@@ -19,11 +17,12 @@ func main() {
panic
(
err
)
panic
(
err
)
}
}
lock_key
:=
"searchapi_6666"
;
//lock_key := "searchapi_668777";
//flag := gredis.Set(lock_key,php2go.Time()+2)
////flag := gredis.Set(lock_key,php2go.Time()+2)
flag
:=
gredis
.
Setnx
(
lock_key
,
2222
)
//flag,_ := gredis.Setnx(lock_key,2222)
fmt
.
Println
(
flag
)
//
os
.
Exit
(
1
)
//fmt.Println(flag)
//os.Exit(1)
dd
:=
service
.
OutLink
(
"LM358"
,
"-1"
)
dd
:=
service
.
OutLink
(
"LM358"
,
"-1"
)
print
(
"niin"
)
print
(
"niin"
)
...
...
conf/redis_key.ini
View file @
ccfbc0bc
...
@@ -6,6 +6,8 @@ SUPPLIER_REDIS_PRE=SUPPLIER_REDIS_INFO_
...
@@ -6,6 +6,8 @@ SUPPLIER_REDIS_PRE=SUPPLIER_REDIS_INFO_
SUPPLIER_REDIS_LIST_PRE
=
SUPPLIER_REDIS_LIST_INFO_
SUPPLIER_REDIS_LIST_PRE
=
SUPPLIER_REDIS_LIST_INFO_
;新增sku时判读sku是否存在
;新增sku时判读sku是否存在
SKU_UNIQUE_JUDGE
=
sku_unique_judge
SKU_UNIQUE_JUDGE
=
sku_unique_judge
;新增sku时判读sku是否存在
SPU_UNIQUE_JUDGE
=
sku_unique_judge
;品牌信息判断,根据md5后的品牌名称获取id
;品牌信息判断,根据md5后的品牌名称获取id
BRAND_NAME_ALL
=
brand_name_all
BRAND_NAME_ALL
=
brand_name_all
;品牌id,获取品牌名称
;品牌id,获取品牌名称
...
...
model/ly.go
View file @
ccfbc0bc
...
@@ -156,10 +156,10 @@ Array
...
@@ -156,10 +156,10 @@ Array
)
)
*/
*/
type
LySpuInfo
struct
{
type
LySpuInfo
struct
{
ClassId1
string
`json:"class_id1"`
//一级分类
ClassId1
int64
`json:"class_id1"`
//一级分类
ClassId2
string
`json:"class_id2"`
//二级分类
ClassId2
int64
`json:"class_id2"`
//二级分类
ClassId3
string
`json:"class_id3"`
//三级分类
ClassId3
int64
`json:"class_id3"`
//三级分类
BrandId
string
`json:"brand_id"`
//品牌ID
BrandId
int64
`json:"brand_id"`
//品牌ID
SpuName
string
`json:"spu_name"`
//型号名称
SpuName
string
`json:"spu_name"`
//型号名称
Status
string
`json:"status"`
// 状态
Status
string
`json:"status"`
// 状态
ImagesL
string
`json:"images_l"`
//图片
ImagesL
string
`json:"images_l"`
//图片
...
...
pkg/gredis/redis.go
View file @
ccfbc0bc
...
@@ -72,27 +72,26 @@ func Set(key string, data interface{}) error {
...
@@ -72,27 +72,26 @@ func Set(key string, data interface{}) error {
}
}
//Redis Setnx(SET if Not eXists) 命令在指定的 key 不存在时,为 key 设置指定的值。
//Redis Setnx(SET if Not eXists) 命令在指定的 key 不存在时,为 key 设置指定的值。
func
Setnx
(
key
string
,
data
interface
{})
error
{
func
Setnx
(
key
string
,
data
interface
{})
(
bool
,
error
)
{
conn
:=
writeConn
.
Get
()
conn
:=
writeConn
.
Get
()
defer
conn
.
Close
()
defer
conn
.
Close
()
value
,
err
:=
json
.
Marshal
(
data
)
value
,
err
:=
json
.
Marshal
(
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
false
,
err
}
_
,
err
=
conn
.
Do
(
"SETNX"
,
key
,
value
)
if
err
!=
nil
{
return
err
}
}
return
redis
.
Bool
(
conn
.
Do
(
"SETNX"
,
key
,
value
))
}
return
nil
//设置过期时间
func
EXP
(
key
string
,
ttl
int
)
(
bool
,
error
)
{
conn
:=
writeConn
.
Get
()
defer
conn
.
Close
()
return
redis
.
Bool
(
conn
.
Do
(
"EXP"
,
key
,
ttl
))
}
}
func
Exists
(
key
string
)
bool
{
func
Exists
(
key
string
)
bool
{
conn
:=
readConn
.
Get
()
conn
:=
readConn
.
Get
()
defer
conn
.
Close
()
defer
conn
.
Close
()
exists
,
err
:=
redis
.
Bool
(
conn
.
Do
(
"EXISTS"
,
key
))
exists
,
err
:=
redis
.
Bool
(
conn
.
Do
(
"EXISTS"
,
key
))
if
err
!=
nil
{
if
err
!=
nil
{
return
false
return
false
...
...
service/common_ly_service.go
View file @
ccfbc0bc
...
@@ -19,6 +19,11 @@ var supplier_over_time = map[string]int64{
...
@@ -19,6 +19,11 @@ var supplier_over_time = map[string]int64{
"tme"
:
3600
,
"tme"
:
3600
,
"buerklin"
:
3600
,
"buerklin"
:
3600
,
}
}
var
sku_uique_judge
string
=
config
.
Get
(
"redis_all.SKU_UNIQUE_JUDGE"
)
.
String
()
//sku唯一键
var
spu_uique_judge
string
=
config
.
Get
(
"redis_all.SPU_UNIQUE_JUDGE"
)
.
String
()
//spu唯一键
var
brand_name_all
string
=
config
.
Get
(
"redis_all.BRAND_NAME_ALL"
)
.
String
()
//品牌键
/*
/*
联营公共类
联营公共类
联营大类,包括修改新增 sku es redis ,推送数据到队列让其他go服务更新数据到mysql
联营大类,包括修改新增 sku es redis ,推送数据到队列让其他go服务更新数据到mysql
...
@@ -28,18 +33,45 @@ var supplier_over_time = map[string]int64{
...
@@ -28,18 +33,45 @@ var supplier_over_time = map[string]int64{
func
getSkuByGoodsSn
(
goods_list
map
[
string
]
*
model
.
LyClearGoodsList
,
supplier_info
*
model
.
SUPPLIER_REDIS_INFO_
)
map
[
string
]
interface
{}{
func
getSkuByGoodsSn
(
goods_list
map
[
string
]
*
model
.
LyClearGoodsList
,
supplier_info
*
model
.
SUPPLIER_REDIS_INFO_
)
map
[
string
]
interface
{}{
originGoods
:=
make
(
map
[
string
]
interface
{},
0
)
originGoods
:=
make
(
map
[
string
]
interface
{},
0
)
sku_uique_judge
:=
config
.
Get
(
"redis_all.SKU_UNIQUE_JUDGE"
)
.
String
()
for
goods_sn
,
info
:=
range
goods_list
{
for
goods_sn
,
info
:=
range
goods_list
{
sn_sku
:=
php2go
.
Md5
(
strings
.
ToLower
(
goods_sn
))
sn_sku
:=
php2go
.
Md5
(
strings
.
ToLower
(
goods_sn
))
sku_id
,
_
:=
gredis
.
HGet
(
sku_uique_judge
,
sn_sku
)
//查询唯一值,反查sku_id
sku_id
,
_
:=
gredis
.
HGet
(
sku_uique_judge
,
sn_sku
)
//查询唯一值,反查sku_id
var
sku_flag
bool
=
false
;
//是否新增或者更新db+redis,为true则新增
if
sku_id
==
""
{
//为空,先创建sku
if
sku_id
==
""
{
//为空,先创建sku
//lock_key := "searchapi_"+sn_sku;
lock_key
:=
"searchapi_"
+
sn_sku
;
//flag := gredis.Setnx(lock_key,php2go.Time()+2)
flag
,
_
:=
gredis
.
Setnx
(
lock_key
,
php2go
.
Time
()
+
2
)
//if flag { //存在锁
if
flag
{
//不存在锁,直接新增
//
sku_flag
=
true
//}
gredis
.
EXP
(
lock_key
,
2
)
//给锁有效时间2秒
sku_id
=
}
else
{
//存在锁
}
/*
if($flag){
$sku_flag = true;
//给锁有效时间
$redis->expire($lock_key,2);
//创建sku_id等信息
$sku_id = $this->writeSkuInfo($v,$redis);
//删除key
$redis->del($lock_key);
}else{
//已经存在锁则等待
$lock_flag = true;
while ($lock_flag){
$lock_flag = $redis->get($lock_key);
usleep(10);
}
$sku_id = $redis->hget(C('SKU_UNIQUE_JUDGE'),$sn_sku);
if(!$sku_id){
continue;
}
}
*/
}
}
print
(
info
)
print
(
info
)
//productList[goodsSn] = &LyClearGoodsList
//productList[goodsSn] = &LyClearGoodsList
...
@@ -49,12 +81,58 @@ func getSkuByGoodsSn(goods_list map[string]*model.LyClearGoodsList,supplier_info
...
@@ -49,12 +81,58 @@ func getSkuByGoodsSn(goods_list map[string]*model.LyClearGoodsList,supplier_info
return
originGoods
return
originGoods
}
}
/*
/*
新增或者更新redis
生成sku信息并写入redis
*/
func
writeSkuInfo
(
sku_info
*
model
.
LyClearGoodsList
)
{
spu_key
:=
php2go
.
Md5
(
sku_info
.
GoodsName
+
"_"
+
sku_info
.
BrandName
)
spu_id
,
_
:=
gredis
.
HGet
(
spu_uique_judge
,
spu_key
)
if
spu_id
==
""
{
//不存在spu,创建新的spu
}
}
/*
生成spu
*/
*/
func
toRedis
()
{
func
writeSpuInfo
(
sku_info
*
model
.
LyClearGoodsList
)
{
brand_key
:=
php2go
.
Md5
(
sku_info
.
BrandName
)
Spuinfo
:=
model
.
LySpuInfo
{
ClassId1
:
0
,
ClassId2
:
0
,
ClassId3
:
0
,
BrandId
:
$
brand_id
,
SpuName
:
$
sku_info
[
'
goods_name
'
],
Status
:
1
,
ImagesL
:
''
,
Encap
:
$
sku_info
[
'
encap
'
]
?
$
sku_info
[
'
encap
'
]
:
''
,
Pdf
:
''
,
SpuBrief
:
''
,
UpdateTime
:
,
}
}
}
/*
/*
生成品牌
*/
func
writeBrandInfo
(
sku_info
*
model
.
LyClearGoodsList
)
{
brand_key
:=
php2go
.
Md5
(
sku_info
.
BrandName
)
Spuinfo
:=
model
.
LySpuInfo
{
ClassId1
:
0
,
ClassId2
:
0
,
ClassId3
:
0
,
BrandId
:
$
brand_id
,
SpuName
:
$
sku_info
[
'
goods_name
'
],
Status
:
1
,
ImagesL
:
''
,
Encap
:
$
sku_info
[
'
encap
'
]
?
$
sku_info
[
'
encap
'
]
:
''
,
Pdf
:
''
,
SpuBrief
:
''
,
UpdateTime
:
,
}
}
/*
推入队列
推入队列
*/
*/
func
toGoRabmq
()
{
func
toGoRabmq
()
{
...
...
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