package trade import ( "time" cache "github.com/patrickmn/go-cache" ) var MemCache *cache.Cache func NewLock() { if MemCache != nil { return } MemCache = cache.New(5*time.Minute, 10*time.Minute) } // 锁仓,可以采用MemCache,Redis,File等。 func IsLock(symbol, side string) bool { lockKey := symbol + ":" + side _, found := MemCache.Get(lockKey) if found { return true } return false } func SetLock(symbol, side string, duration int64) { MemCache.Set(symbol+":"+side, true, time.Duration(duration)*time.Second) }