Commit 089db914 by 孙龙

Merge branch 'dev' of http://119.23.72.7/mushishixian/search_server into dev

parents 71579d9f 9c68f844
package main package main
import ( import (
"flag"
"fmt"
"os" "os"
"search_server/boot"
"search_server/pkg/gredis"
"search_server/service" "search_server/service"
) )
func main() { func main() {
//MouserService := service.NewMouserServiceImpl() //MouserService := service.NewMouserServiceImpl()
//MouserGetData(MouserService) //MouserGetData(MouserService)
var path string
flag.StringVar(&path, "config", "conf", "配置文件")
flag.Parse()
if err := boot.Boot(path); err != nil {
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)
dd := service.OutLink("LM358","-1") dd := service.OutLink("LM358","-1")
print("niin") print("niin")
print(dd) print(dd)
......
...@@ -91,6 +91,24 @@ func Set(key string, data interface{}) error { ...@@ -91,6 +91,24 @@ func Set(key string, data interface{}) error {
return nil return nil
} }
//Redis Setnx(SET if Not eXists) 命令在指定的 key 不存在时,为 key 设置指定的值。
func Setnx(key string, data interface{}) 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 nil
}
func Exists(key string) bool { func Exists(key string) bool {
conn := readConn.Get() conn := readConn.Get()
defer conn.Close() defer conn.Close()
......
package service package service
import ( import (
_ "fmt" "fmt"
"github.com/syyongx/php2go"
_ "github.com/tidwall/gjson" _ "github.com/tidwall/gjson"
"search_server/model" "search_server/model"
_ "search_server/pkg/gredis" "search_server/pkg/gredis"
"search_server/pkg/config"
"strings"
) )
//关键词搜索过期时间 //关键词搜索过期时间
...@@ -24,19 +27,26 @@ var supplier_over_time = map[string]int64{ ...@@ -24,19 +27,26 @@ 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, goods_list := range goods_list {
// gredis.HGet("") for goods_sn, info := range goods_list {
//
// ladderPrice := make([]*model.TierItem, 0) sn_sku := php2go.Md5(strings.ToLower(goods_sn))
// sku_id,_ := gredis.HGet(sku_uique_judge,sn_sku) //查询唯一值,反查sku_id
// productList[goodsSn] = &LyClearGoodsList if sku_id == "" { //为空,先创建sku
//} //lock_key := "searchapi_"+sn_sku;
// //flag := gredis.Setnx(lock_key,php2go.Time()+2)
//fmt.Println(productList) //if flag { //存在锁
//return productList //
return nil //}
}
print(info)
//productList[goodsSn] = &LyClearGoodsList
}
fmt.Println(originGoods)
return originGoods
} }
/* /*
新增或者更新redis 新增或者更新redis
......
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