Commit ccfbc0bc by huangchengyi

1.0

parent 9c68f844
......@@ -2,10 +2,8 @@ package main
import (
"flag"
"fmt"
"os"
"search_server/boot"
"search_server/pkg/gredis"
"search_server/service"
)
......@@ -19,11 +17,12 @@ func main() {
panic(err)
}
lock_key := "searchapi_6666";
//flag := gredis.Set(lock_key,php2go.Time()+2)
flag := gredis.Setnx(lock_key,2222)
fmt.Println(flag)
os.Exit(1)
//lock_key := "searchapi_668777";
////flag := gredis.Set(lock_key,php2go.Time()+2)
//flag,_ := gredis.Setnx(lock_key,2222)
//
//fmt.Println(flag)
//os.Exit(1)
dd := service.OutLink("LM358","-1")
print("niin")
......
......@@ -6,6 +6,8 @@ SUPPLIER_REDIS_PRE=SUPPLIER_REDIS_INFO_
SUPPLIER_REDIS_LIST_PRE=SUPPLIER_REDIS_LIST_INFO_
;新增sku时判读sku是否存在
SKU_UNIQUE_JUDGE=sku_unique_judge
;新增sku时判读sku是否存在
SPU_UNIQUE_JUDGE=sku_unique_judge
;品牌信息判断,根据md5后的品牌名称获取id
BRAND_NAME_ALL=brand_name_all
;品牌id,获取品牌名称
......
......@@ -156,10 +156,10 @@ Array
)
*/
type LySpuInfo struct {
ClassId1 string `json:"class_id1"` //一级分类
ClassId2 string `json:"class_id2"` //二级分类
ClassId3 string `json:"class_id3"` //三级分类
BrandId string `json:"brand_id"` //品牌ID
ClassId1 int64 `json:"class_id1"` //一级分类
ClassId2 int64 `json:"class_id2"` //二级分类
ClassId3 int64 `json:"class_id3"` //三级分类
BrandId int64 `json:"brand_id"` //品牌ID
SpuName string `json:"spu_name"` //型号名称
Status string `json:"status"` // 状态
ImagesL string `json:"images_l"` //图片
......
......@@ -72,27 +72,26 @@ func Set(key string, data interface{}) error {
}
//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()
defer conn.Close()
value, err := json.Marshal(data)
if err != nil {
return err
}
_, err = conn.Do("SETNX", key, value)
if err != nil {
return err
return false,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 {
conn := readConn.Get()
defer conn.Close()
exists, err := redis.Bool(conn.Do("EXISTS", key))
if err != nil {
return false
......
......@@ -19,6 +19,11 @@ var supplier_over_time = map[string]int64{
"tme":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
......@@ -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{}{
originGoods := make(map[string]interface{},0)
sku_uique_judge := config.Get("redis_all.SKU_UNIQUE_JUDGE").String()
for goods_sn, info := range goods_list {
sn_sku := php2go.Md5(strings.ToLower(goods_sn))
sku_id,_ := gredis.HGet(sku_uique_judge,sn_sku) //查询唯一值,反查sku_id
var sku_flag bool = false; //是否新增或者更新db+redis,为true则新增
if sku_id == "" { //为空,先创建sku
//lock_key := "searchapi_"+sn_sku;
//flag := gredis.Setnx(lock_key,php2go.Time()+2)
//if flag { //存在锁
//
//}
lock_key := "searchapi_"+sn_sku;
flag,_ := gredis.Setnx(lock_key,php2go.Time()+2)
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)
//productList[goodsSn] = &LyClearGoodsList
......@@ -49,12 +81,58 @@ func getSkuByGoodsSn(goods_list map[string]*model.LyClearGoodsList,supplier_info
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() {
......
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