33 lines
693 B
Go
33 lines
693 B
Go
package storeskulock
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
)
|
|
|
|
const (
|
|
cacheKeyPrefix = "jdpromotion"
|
|
)
|
|
|
|
func LockJdStoreSku(storeID, skuID int, expire time.Time) {
|
|
globals.SugarLogger.Debug(expire, " ", time.Now())
|
|
duration := expire.Sub(time.Now())
|
|
if duration > 0 {
|
|
globals.Cacher.Set(genCacheKey(storeID, skuID), 1, duration)
|
|
}
|
|
}
|
|
|
|
func UnlockJdStoreSku(storeID, skuID int) {
|
|
globals.Cacher.Del(genCacheKey(storeID, skuID))
|
|
}
|
|
|
|
func IsJdStoreSkuLocked(storeID, skuID int) bool {
|
|
return globals.Cacher.Get(genCacheKey(storeID, skuID)) != nil
|
|
}
|
|
|
|
func genCacheKey(storeID, skuID int) string {
|
|
return fmt.Sprintf("%s.%d.%d", cacheKeyPrefix, storeID, skuID)
|
|
}
|