Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] rate.NewSemaphore: type conversion failure (MakeRedisClient error?) #790

Closed
gwkline opened this issue Nov 29, 2023 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@gwkline
Copy link

gwkline commented Nov 29, 2023

Describe the bug
When trying to create a new semaphore using the rate package, I am getting the following error:

rate.NewSemaphore: unsupported RedisConnOpt type asynq.RedisClientOpt

I believe this is happening because calling asynq.MakeRedisClient() on a asynq.RedisClientOpt is returning a *redis.Client which doesn't implement all methods required by redis.UniversalClient. Maybe this is because of a mismatch between the go-redis version? I'm not quite sure.

To Reproduce

package scripts

import (
	"context"
	"fmt"
	"os"

	"my-app/pkg/task"
	"github.com/hibiken/asynq"
	"github.com/hibiken/asynq/x/rate"

	"github.com/redis/go-redis/v9" // also fails on v8
)

func (s *Service) SomeFunc(ctx context.Context) error {
	ops, err := redis.ParseURL(os.Getenv("REDIS_URL"))
	if err != nil {
		fmt.Printf("failed parsing redis: %v", err)
	}

	asynqOps := asynq.RedisClientOpt{
		Addr:     ops.Addr,
		DB:       ops.DB,
		Password: ops.Password,
		Username: ops.Username,
	}
	
	//....

         semaphore := rate.NewSemaphore(asynqOps, "someKey", 50) //error is happening in here**
		
	//....
}

Expected behavior
When passing a valid asynq.RedisClientOpt to rate.NewSemaphore, there should not be a type coercion error.

Environment (please complete the following information):

  • OS: Alpine (golang:alpine docker image)
require (
	github.com/99designs/gqlgen v0.17.40
	github.com/DATA-DOG/go-sqlmock v1.5.0
	github.com/PuerkitoBio/goquery v1.8.1
	github.com/badoux/checkmail v1.2.1
	github.com/davecgh/go-spew v1.1.1
	github.com/getsentry/sentry-go v0.25.0
	github.com/gin-contrib/cors v1.5.0
	github.com/gin-contrib/pprof v1.4.0
	github.com/gin-gonic/gin v1.9.1
	github.com/go-redis/redis/v8 v8.11.4
	github.com/gocolly/colly v1.2.0
	github.com/golang-jwt/jwt v3.2.2+incompatible
	github.com/google/uuid v1.4.0
	github.com/hibiken/asynq v0.24.1
	github.com/hibiken/asynq/x v0.0.0-20211219150637-8dfabfccb3be
	github.com/hibiken/asynqmon v0.7.2
	github.com/lib/pq v1.10.9
	github.com/masatana/go-textdistance v0.0.0-20191005053614-738b0edac985
	github.com/pquerna/otp v1.4.0
	github.com/redis/go-redis/v9 v9.3.0
	github.com/stretchr/testify v1.8.4
	github.com/vektah/gqlparser/v2 v2.5.10
	golang.org/x/crypto v0.16.0
	golang.org/x/text v0.14.0
	gorm.io/driver/postgres v1.5.4
	gorm.io/gorm v1.25.5
)
@kamikazechaser
Copy link
Collaborator

kamikazechaser commented Dec 6, 2023

Looking at your environment, The x package is not compatible with v0.24.x at the moment. I can see we reverted it back to go-redis/v8. Could you try running your snippet when compiled with an older version of github.com/hibiken/asynq?

@kamikazechaser
Copy link
Collaborator

Could you test #796 and let me know if it fixes this issue.

cc/ @amaury1729

@gwkline
Copy link
Author

gwkline commented Dec 7, 2023

@kamikazechaser #796 does appear to solve this issue!

@gwkline gwkline closed this as completed Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants