mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
locker
This commit is contained in:
31
locker/redis/redis_store_test.go
Normal file
31
locker/redis/redis_store_test.go
Normal file
@ -0,0 +1,31 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/charlienet/go-mixed/redis"
|
||||
"github.com/charlienet/go-mixed/tests"
|
||||
)
|
||||
|
||||
func TestCreateRedisStore(t *testing.T) {
|
||||
tests.RunOnDefaultRedis(t, func(rdb redis.Client) {
|
||||
keyName := "source"
|
||||
|
||||
l := NewRedisStore("locker_key", rdb)
|
||||
ret := l.TryLock(context.Background(), keyName)
|
||||
if !ret {
|
||||
t.Log("加锁失败")
|
||||
}
|
||||
|
||||
l.Lock(context.Background(), keyName)
|
||||
t.Log("锁重入完成")
|
||||
|
||||
l.Unlock(context.Background(), keyName)
|
||||
|
||||
time.Sleep(time.Second * 15)
|
||||
|
||||
// l.Unlock(context.Background())
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user