mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-24 06:42:16 +08:00
Change NewClient API to take *redis.Client
This commit is contained in:
parent
ae0c2f9ca5
commit
62624cb0d8
@ -50,9 +50,10 @@ import "github.com/hibiken/asynq"
|
||||
|
||||
```go
|
||||
func main() {
|
||||
client := asynq.NewClient(&asynq.RedisOpt{
|
||||
r := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
})
|
||||
}
|
||||
client := asynq.NewClient(r)
|
||||
|
||||
t1 := asynq.Task{
|
||||
Type: "send_welcome_email",
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v7"
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
@ -17,10 +18,11 @@ func TestBackground(t *testing.T) {
|
||||
DB: 15,
|
||||
})
|
||||
|
||||
client := NewClient(&RedisConfig{
|
||||
r := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
DB: 15,
|
||||
})
|
||||
client := NewClient(r)
|
||||
|
||||
// no-op handler
|
||||
h := func(task *Task) error {
|
||||
|
@ -3,6 +3,7 @@ package asynq
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v7"
|
||||
"github.com/hibiken/asynq/internal/base"
|
||||
"github.com/hibiken/asynq/internal/rdb"
|
||||
"github.com/rs/xid"
|
||||
@ -19,9 +20,9 @@ type Client struct {
|
||||
}
|
||||
|
||||
// NewClient and returns a new Client given a redis configuration.
|
||||
func NewClient(cfg *RedisConfig) *Client {
|
||||
r := rdb.NewRDB(newRedisClient(cfg))
|
||||
return &Client{r}
|
||||
func NewClient(r *redis.Client) *Client {
|
||||
rdb := rdb.NewRDB(r)
|
||||
return &Client{rdb}
|
||||
}
|
||||
|
||||
// Option configures the behavior of task processing.
|
||||
|
@ -7,12 +7,11 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
h "github.com/hibiken/asynq/internal/asynqtest"
|
||||
"github.com/hibiken/asynq/internal/base"
|
||||
"github.com/hibiken/asynq/internal/rdb"
|
||||
)
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
r := setup(t)
|
||||
client := &Client{rdb.NewRDB(r)}
|
||||
client := NewClient(r)
|
||||
|
||||
task := &Task{Type: "send_email", Payload: map[string]interface{}{"to": "customer@gmail.com", "from": "merchant@example.com"}}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user