Files
jx-callback/business/jxutils/storeskulock/storeskulock.go
2018-11-06 16:10:23 +08:00

33 lines
761 B
Go

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