Skip to content

Commit

Permalink
update example and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
amyangfei committed Jan 8, 2021
1 parent 85a3132 commit 1adb255
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -40,7 +40,7 @@ To acquire a lock:
import "github.com/amyangfei/redlock-go/v2/redlock"

ctx := context.Background()
expirity, err := lockMgr.Lock(ctx, "resource_name", 200)
expirity, err := lockMgr.Lock(ctx, "resource_name", 200*time.Milliseconds)
```

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.
Expand Down
5 changes: 3 additions & 2 deletions _examples/basic.go
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"time"

"github.com/amyangfei/redlock-go/v2/redlock"
)
Expand All @@ -19,11 +20,11 @@ func main() {
}

ctx := context.Background()
expiry, err := lock.Lock(ctx, "foo", 200)
expiry, err := lock.Lock(ctx, "foo", 200*time.Millisecond)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("got lock, with expiry %d ms\n", expiry)
fmt.Printf("got lock, with expiry %s\n", expiry)
}
defer lock.UnLock(ctx, "foo")
}
3 changes: 2 additions & 1 deletion _examples/counter.go
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"strconv"
"strings"
"time"

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

incr := 0
for i := 0; i < count; i++ {
expiry, err := lock.Lock(ctx, "foo", 1000)
expiry, err := lock.Lock(ctx, "foo", 1000*time.Millisecond)
if err != nil {
fmt.Println(err)
} else {
Expand Down

0 comments on commit 1adb255

Please sign in to comment.