From 62624cb0d8e70e2ffa2d6052f187c5a4b648789e Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Sun, 29 Dec 2019 13:42:49 -0800 Subject: [PATCH] Change NewClient API to take *redis.Client --- README.md | 5 +++-- background_test.go | 4 +++- client.go | 7 ++++--- client_test.go | 3 +-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 953e3b8..767cf5a 100644 --- a/README.md +++ b/README.md @@ -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", diff --git a/background_test.go b/background_test.go index 4a525b0..263627f 100644 --- a/background_test.go +++ b/background_test.go @@ -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 { diff --git a/client.go b/client.go index aa518e6..e51e385 100644 --- a/client.go +++ b/client.go @@ -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. diff --git a/client_test.go b/client_test.go index 1c861f0..0f6b04d 100644 --- a/client_test.go +++ b/client_test.go @@ -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"}}