mirror of
https://github.com/hibiken/asynq.git
synced 2024-11-10 11:31:58 +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
|
```go
|
||||||
func main() {
|
func main() {
|
||||||
client := asynq.NewClient(&asynq.RedisOpt{
|
r := redis.NewClient(&redis.Options{
|
||||||
Addr: "localhost:6379",
|
Addr: "localhost:6379",
|
||||||
})
|
}
|
||||||
|
client := asynq.NewClient(r)
|
||||||
|
|
||||||
t1 := asynq.Task{
|
t1 := asynq.Task{
|
||||||
Type: "send_welcome_email",
|
Type: "send_welcome_email",
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-redis/redis/v7"
|
||||||
"go.uber.org/goleak"
|
"go.uber.org/goleak"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,10 +18,11 @@ func TestBackground(t *testing.T) {
|
|||||||
DB: 15,
|
DB: 15,
|
||||||
})
|
})
|
||||||
|
|
||||||
client := NewClient(&RedisConfig{
|
r := redis.NewClient(&redis.Options{
|
||||||
Addr: "localhost:6379",
|
Addr: "localhost:6379",
|
||||||
DB: 15,
|
DB: 15,
|
||||||
})
|
})
|
||||||
|
client := NewClient(r)
|
||||||
|
|
||||||
// no-op handler
|
// no-op handler
|
||||||
h := func(task *Task) error {
|
h := func(task *Task) error {
|
||||||
|
@ -3,6 +3,7 @@ package asynq
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-redis/redis/v7"
|
||||||
"github.com/hibiken/asynq/internal/base"
|
"github.com/hibiken/asynq/internal/base"
|
||||||
"github.com/hibiken/asynq/internal/rdb"
|
"github.com/hibiken/asynq/internal/rdb"
|
||||||
"github.com/rs/xid"
|
"github.com/rs/xid"
|
||||||
@ -19,9 +20,9 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewClient and returns a new Client given a redis configuration.
|
// NewClient and returns a new Client given a redis configuration.
|
||||||
func NewClient(cfg *RedisConfig) *Client {
|
func NewClient(r *redis.Client) *Client {
|
||||||
r := rdb.NewRDB(newRedisClient(cfg))
|
rdb := rdb.NewRDB(r)
|
||||||
return &Client{r}
|
return &Client{rdb}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option configures the behavior of task processing.
|
// Option configures the behavior of task processing.
|
||||||
|
@ -7,12 +7,11 @@ import (
|
|||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
h "github.com/hibiken/asynq/internal/asynqtest"
|
h "github.com/hibiken/asynq/internal/asynqtest"
|
||||||
"github.com/hibiken/asynq/internal/base"
|
"github.com/hibiken/asynq/internal/base"
|
||||||
"github.com/hibiken/asynq/internal/rdb"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestClient(t *testing.T) {
|
func TestClient(t *testing.T) {
|
||||||
r := setup(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"}}
|
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