Commit 293be8a5 by yemin

no message

parent 2c7ba0f6
......@@ -148,6 +148,25 @@ func Unlock(k, uniqueValue string) bool {
return false
}
// LockWait 抢锁,在规定的时间内直到抢锁成功或者超时失败。抢到锁返回true,否则false
// k 必须
// uniqueValue 必须
// timeoutSecond 锁自动释放时间,必须
// lockTimeoutSecond 抢锁超时时间,默认1分钟
func LockWait(k, uniqueValue string, timeoutSecond int, lockTimeoutSecond int) bool {
if lockTimeoutSecond == 0 {
lockTimeoutSecond = 60
}
loopCount := lockTimeoutSecond * 10
for i := 0; i < loopCount; i++ {
if Lock(k, uniqueValue, timeoutSecond) {
return true
}
time.Sleep(time.Duration(100) * time.Millisecond) //100ms
}
return false
}
// Hset 向一张hash表中放入数据,如果不存在将创建
func Hset(k, i, v string, timeoutSecond int) error {
e := getDb().HSet(k, i, v).Err()
......
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 to comment