Open yun36524 opened 2 years ago
Can you paste the code? Let me have a look? @yun36524
I think there is a problem with your Redis port port:6379 ?
I think there is a problem with your Redis port port:6379 ?
I'm sure there's nothing wrong with redis because my application is using it properly. I am copying the official code and it does not work.
func InitServer() {
srv := asynq.NewServer(
asynq.RedisClientOpt{Addr: "127.0.0.1:63791", Password: "***", ReadTimeout: 10 * time.Second, WriteTimeout: 0},
asynq.Config{
// Specify how many concurrent workers to use
Concurrency: 10,
// Optionally specify multiple queues with different priority.
Queues: map[string]int{
"critical": 6,
"default": 3,
"low": 1,
},
// See the godoc for other configuration options
},
)
// mux maps a type to a handler
mux := asynq.NewServeMux()
mux.HandleFunc("msg", HandleEmailDeliveryTask)
// ...register other handlers...
if err := srv.Run(mux); err != nil {
log.Fatalf("could not run server: %v", err)
}
}
func HandleEmailDeliveryTask(ctx context.Context, t *asynq.Task) error {
fmt.Println("----------------")
// Email delivery code ...
return nil
}
Anybody here?
I used your code, but it didn't reproduce. The suspicion is still related to Redis....
I used your code, but it didn't reproduce. The suspicion is still related to Redis....
I can run this code normally. Is there any configuration to pay attention to in redis?
import(
"github.com/go-redis/redis/v8"
"fmt"
)
func main(){
client := redis.NewClient(&redis.Options{
Addr: "127.0.0.1:63791",
Password: "***",
})
client.SetNX(context.Background(), "msg", "hello", 10*time.Second)
fmt.Println(client.Get(context.Background(), "msg"))
}
Can someone help me
@yun36524 This is how I manage redis client, don't know if this will work for you:
import (
"github.com/go-redis/redis/v8"
"github.com/hibiken/asynq"
)
type CloseNopClient struct {
redis.UniversalClient
}
// Close do nothing
// asynq.Scheduler Shutdown() will call client.Close()
func (c *CloseNopClient) Close() error {
return nil
}
type clientHolder struct {
client redis.UniversalClient
}
var _ asynq.RedisConnOpt = (*clientHolder)(nil)
func (opt clientHolder) MakeRedisClient() interface{} {
return opt.client
}
func NewRedisConnOpt(client redis.UniversalClient) asynq.RedisConnOpt {
return &clientHolder{
client: &CloseNopClient{
UniversalClient: client,
},
}
}
func Example() {
client := redis.NewClient(&redis.Options{
Addr: "127.0.0.1:63791",
Password: "***",
})
srv := asynq.NewServer(
NewRedisConnOpt(client),
asynq.Config{
// Specify how many concurrent workers to use
Concurrency: 10,
// Optionally specify multiple queues with different priority.
Queues: map[string]int{
"critical": 6,
"default": 3,
"low": 1,
},
// See the godoc for other configuration options
},
)
}
If you use a mac, I suggest you re install redis with brew!!!!!
I have the same problem and hope to get help. Redis is installed with Docker. Redis is normally in use
@hibiken Hi,about the problem.I found that it is related to the redis option. when db>0 log print "discarding bad PubSub connection" db=0 ,password="" don't print. db=0 password="xxxx" log print "discarding bad PubSub connection"
Can someone help me
My solution is: asynq.NewServer( asynq.RedisClientOpt{Addr: "127.0.0.1:63791", Password: "***", ReadTimeout: -1, WriteTimeout: 0}............................
ReadTimeout set -1,won't print anymore
use localhost,,,
redis: discarding bad PubSub connection: read tcp 127.0.0.1:52914->127.0.0.1:63791: i/o timeout I can't run it, my redis is working fine