Open sprabowo opened 3 weeks ago
kindly review this small change for exposing MinIdleConns redis config @hibiken @kamikazechaser
@sprabowo You can override the asynq go-redis client and bring your own with MakeRedisClient
with all custom options that are not otherwise not exposed.
Perhaps we could document that rather that individually add opts.
@kamikazechaser IIRC, should this be handled on app instead of this lib?
i was trying to make my own MustNewClient. it turns out, it does not work.
here are my finding:
could not import github.com/hibiken/asynq/internal/rdb (invalid use of internal package "github.com/hibiken/asynq/internal/rdb")
. thus i still propose to just add additional config rather re-implement this CMIIW
// asynq/asynq.go
package asynq
import (
"crypto/tls"
"time"
"github.com/go-redis/redis/v7"
)
type MustRedisConnOpt interface {
MustMakeRedisClient() interface{}
}
type MustRedisClientOpt struct {
Network string
Addr string
Username string
Password string
DB int
DialTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
PoolSize int
MinIdleConn int
TLSConfig *tls.Config
}
func (opt MustRedisClientOpt) MustMakeRedisClient() interface{} {
return redis.NewClient(&redis.Options{
Network: opt.Network,
Addr: opt.Addr,
Username: opt.Username,
Password: opt.Password,
DB: opt.DB,
DialTimeout: opt.DialTimeout,
WriteTimeout: opt.WriteTimeout,
PoolSize: opt.PoolSize,
MinIdleConns: opt.MinIdleConn,
TLSConfig: opt.TLSConfig,
})
}
// asynq/client.go
package asynq
import (
"fmt"
"github.com/go-redis/redis/v7"
"github.com/hibiken/asynq/internal/rdb"
)
type Client struct {
rdb *rdb.RDB
}
func MustNewClient(r MustRedisConnOpt) *Client {
c, ok := r.MustMakeRedisClient().(redis.UniversalClient)
if !ok {
panic(fmt.Sprintf("asynq: unsupported RedisConnOpt type %T", r))
}
return &Client{rdb: rdb.NewRDB(c)}
}
MustNewClient implementation. this doesn't work
any suggestions @kamikazechaser @hibiken? really appreciate it
context: i want to have min idle conns config available on asynq. asynq uses go-redis@v9 which support MinIdleConns.
changelog: