()
| 65 | } |
| 66 | |
| 67 | func ExampleClient_Obtain_retry() { |
| 68 | client := redis.NewClient(&redis.Options{Network: "tcp", Addr: "127.0.0.1:6379"}) |
| 69 | defer client.Close() |
| 70 | |
| 71 | locker := redislock.New(client) |
| 72 | |
| 73 | ctx := context.Background() |
| 74 | |
| 75 | // Retry every 100ms, for up-to 3x |
| 76 | backoff := redislock.LimitRetry(redislock.LinearBackoff(100*time.Millisecond), 3) |
| 77 | |
| 78 | // Obtain lock with retry |
| 79 | lock, err := locker.Obtain(ctx, "my-key", time.Second, &redislock.Options{ |
| 80 | RetryStrategy: backoff, |
| 81 | }) |
| 82 | if err == redislock.ErrNotObtained { |
| 83 | fmt.Println("Could not obtain lock!") |
| 84 | } else if err != nil { |
| 85 | log.Fatalln(err) |
| 86 | } |
| 87 | defer lock.Release(ctx) |
| 88 | |
| 89 | fmt.Println("I have a lock!") |
| 90 | } |
| 91 | |
| 92 | func ExampleLock_Refresh_watchdog() { |
| 93 | client := redis.NewClient(&redis.Options{Network: "tcp", Addr: "127.0.0.1:6379"}) |
nothing calls this directly
no test coverage detected