Commit ed7e60aa by wang

test requests

parent e0f1e80b
......@@ -46,3 +46,4 @@ func GetSkuListPrice(ctx *gin.Context) {
e.CheckError(err)
common.NResponse("",0,rsp).OutPut(ctx)
}
package controller
import (
"github.com/gin-gonic/gin"
"golang_open_platform/pkg/common"
"golang_open_platform/pkg/gredis"
)
func TestRequest(ctx *gin.Context) {
ctx.JSON(200,nil)
}
//如果锁不存在并设置锁
func addOnlyLock(key string){
redisWriteConn := gredis.Conn("search_w")
defer redisWriteConn.Close()
name:="flow_lock_"+key
//common.PrintStdout().Printf("加锁 key:%s",name)
for{
s, err:= redisWriteConn.Do("SET", name, "1", "EX", "10","NX")//锁两秒没主动删就自动关闭(防止某个流程卡死,没执行到删除锁)
if(err!=nil){
common.PrintStdout().Printf("读取redis 锁 key:%d 报错",key)
}
if(s!=nil){
//common.PrintStdout().Printf("加锁完成 key :%s",name)
break
}
}
}
//删除锁
func delOnlyLock(key string){
redisWriteConn := gredis.Conn("search_w")
defer redisWriteConn.Close()
name:="flow_lock_"+key
_, err:= redisWriteConn.Do("DEL", name)
if(err!=nil){
println(err.Error())
}
//common.PrintStdout().Printf("解锁完成")
}
\ No newline at end of file
......@@ -26,6 +26,6 @@ func InitRouter() *gin.Engine {
r.GET("GetSkuListPrice",controller.Error_Middleware("sku_query"),
controller.Open_Middleware("GetSkuListPrice"),controller.GetSkuListPrice)
//
r.GET("Test",controller.Error_Middleware("sku_query"),controller.TestRequest)
return r
}
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