2023-06-04 22:54:54 +08:00

41 lines
672 B
Go

package redis
import (
"context"
"fmt"
"testing"
"time"
)
func TestGet(t *testing.T) {
Set("syj1", "123", time.Duration(10)*time.Second)
Set("syj2", "123", time.Duration(8000)*time.Millisecond)
fmt.Println(Get("syj1"))
go func() {
Lock("syj3", time.Duration(10)*time.Second, func() {
demo("123")
})
}()
go func() {
Lock("syj3", time.Duration(10)*time.Second, func() {
demo("456")
})
}()
time.Sleep(time.Duration(3) * time.Second)
}
func demo(val string) {
time.Sleep(time.Duration(10) * time.Millisecond)
fmt.Println("I achieve chance : ", val)
}
var ctx = context.Background()
func TestD11(t *testing.T) {
fmt.Println(Get("key"))
}