Skip to content

Commit 1adb255

Browse files
committed
update example and readme
1 parent 85a3132 commit 1adb255

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ To acquire a lock:
4040
import "github.com/amyangfei/redlock-go/v2/redlock"
4141

4242
ctx := context.Background()
43-
expirity, err := lockMgr.Lock(ctx, "resource_name", 200)
43+
expirity, err := lockMgr.Lock(ctx, "resource_name", 200*time.Milliseconds)
4444
```
4545

4646
Where the resource name is an unique identifier of what you are trying to lock and 200 is the number of milliseconds for the validity time.

_examples/basic.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"time"
67

78
"github.com/amyangfei/redlock-go/v2/redlock"
89
)
@@ -19,11 +20,11 @@ func main() {
1920
}
2021

2122
ctx := context.Background()
22-
expiry, err := lock.Lock(ctx, "foo", 200)
23+
expiry, err := lock.Lock(ctx, "foo", 200*time.Millisecond)
2324
if err != nil {
2425
fmt.Println(err)
2526
} else {
26-
fmt.Printf("got lock, with expiry %d ms\n", expiry)
27+
fmt.Printf("got lock, with expiry %s\n", expiry)
2728
}
2829
defer lock.UnLock(ctx, "foo")
2930
}

_examples/counter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"strconv"
88
"strings"
9+
"time"
910

1011
"github.com/amyangfei/redlock-go/v2/redlock"
1112
)
@@ -28,7 +29,7 @@ func writer(count int, back chan string) {
2829

2930
incr := 0
3031
for i := 0; i < count; i++ {
31-
expiry, err := lock.Lock(ctx, "foo", 1000)
32+
expiry, err := lock.Lock(ctx, "foo", 1000*time.Millisecond)
3233
if err != nil {
3334
fmt.Println(err)
3435
} else {

0 commit comments

Comments
 (0)