()
| 132 | } |
| 133 | |
| 134 | func ExampleClient_Obtain_customDeadline() { |
| 135 | client := redis.NewClient(&redis.Options{Network: "tcp", Addr: "127.0.0.1:6379"}) |
| 136 | defer client.Close() |
| 137 | |
| 138 | locker := redislock.New(client) |
| 139 | |
| 140 | // Retry every 500ms, for up-to a minute |
| 141 | backoff := redislock.LinearBackoff(500 * time.Millisecond) |
| 142 | ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Minute)) |
| 143 | defer cancel() |
| 144 | |
| 145 | // Obtain lock with retry + custom deadline |
| 146 | lock, err := locker.Obtain(ctx, "my-key", time.Second, &redislock.Options{ |
| 147 | RetryStrategy: backoff, |
| 148 | }) |
| 149 | if err == redislock.ErrNotObtained { |
| 150 | fmt.Println("Could not obtain lock!") |
| 151 | } else if err != nil { |
| 152 | log.Fatalln(err) |
| 153 | } |
| 154 | defer lock.Release(context.Background()) |
| 155 | |
| 156 | fmt.Println("I have a lock!") |
| 157 | } |
nothing calls this directly
no test coverage detected