Files
lockx/locks_test.go
T

35 lines
603 B
Go

package lockx_test
import (
"context"
"fmt"
"testing"
"github.com/redis/go-redis/v9"
"github.com/yuninks/lockx"
)
func TestSimpleLock(t *testing.T) {
ctx := context.Background()
client := redis.NewClient(&redis.Options{
Addr: "127.0.0.1" + ":" + "6379",
Password: "123456", // no password set
DB: 0, // use default DB
})
if client == nil {
fmt.Println("redis init error")
return
}
lockx.Init(ctx, client)
l, err := lockx.New(ctx, "lockx:test")
if err != nil {
t.Log(err)
return
}
if b, _ := l.Lock(); b {
fmt.Println("lock success")
l.Unlock()
}
}