Skip to content

Commit

Permalink
docs: add example of universal redis client to readme (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRoesler authored May 23, 2023
1 parent d5760b6 commit 3ac6cc2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
local
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,43 @@ func main() {
s.StartBlocking()
}
```

The redis UniversalClient can also be used

```go
package main

import (
"fmt"
"time"

"github.com/go-co-op/gocron"
"github.com/redis/go-redis/v9"

redislock "github.com/go-co-op/gocron-redis-lock"
)

func main() {
redisOptions := &redis.UniversalOptions{
Addrs: []string{"localhost:6379"},
}
redisClient := redis.NewUniversalClient(redisOptions)
locker, err := redislock.NewRedisLocker(redisClient, redislock.WithTries(1))
if err != nil {
// handle the error
}

s := gocron.NewScheduler(time.UTC)
s.WithDistributedLocker(locker)

_, err = s.Every("1s").Name("unique_name").Do(func() {
// task to do
fmt.Println("call 1s")
})
if err != nil {
// handle the error
}

s.StartBlocking()
}
```

0 comments on commit 3ac6cc2

Please sign in to comment.