initial
This commit is contained in:
30
trade/lock.go
Normal file
30
trade/lock.go
Normal file
@@ -0,0 +1,30 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user