mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-26 07:42:17 +08:00
Add DB field to RedisOpt to specify redis db index
This commit is contained in:
parent
d5c2b9b995
commit
f91004e6aa
3
asynq.go
3
asynq.go
@ -54,4 +54,7 @@ type taskMessage struct {
|
|||||||
type RedisOpt struct {
|
type RedisOpt struct {
|
||||||
Addr string
|
Addr string
|
||||||
Password string
|
Password string
|
||||||
|
|
||||||
|
// DB specifies which redis database to select.
|
||||||
|
DB int
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,11 @@ type Background struct {
|
|||||||
|
|
||||||
// NewBackground returns a new Background instance.
|
// NewBackground returns a new Background instance.
|
||||||
func NewBackground(numWorkers int, opt *RedisOpt) *Background {
|
func NewBackground(numWorkers int, opt *RedisOpt) *Background {
|
||||||
client := redis.NewClient(&redis.Options{Addr: opt.Addr, Password: opt.Password})
|
client := redis.NewClient(&redis.Options{
|
||||||
|
Addr: opt.Addr,
|
||||||
|
Password: opt.Password,
|
||||||
|
DB: opt.DB,
|
||||||
|
})
|
||||||
rdb := newRDB(client)
|
rdb := newRDB(client)
|
||||||
poller := newPoller(rdb, 5*time.Second, []string{scheduled, retry})
|
poller := newPoller(rdb, 5*time.Second, []string{scheduled, retry})
|
||||||
processor := newProcessor(rdb, numWorkers, nil)
|
processor := newProcessor(rdb, numWorkers, nil)
|
||||||
|
@ -14,7 +14,11 @@ type Client struct {
|
|||||||
|
|
||||||
// NewClient creates and returns a new client.
|
// NewClient creates and returns a new client.
|
||||||
func NewClient(opt *RedisOpt) *Client {
|
func NewClient(opt *RedisOpt) *Client {
|
||||||
client := redis.NewClient(&redis.Options{Addr: opt.Addr, Password: opt.Password})
|
client := redis.NewClient(&redis.Options{
|
||||||
|
Addr: opt.Addr,
|
||||||
|
Password: opt.Password,
|
||||||
|
DB: opt.DB,
|
||||||
|
})
|
||||||
return &Client{rdb: newRDB(client)}
|
return &Client{rdb: newRDB(client)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user