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

Closed
opened 2026-03-07 22:09:13 +03:00 by kerem · 3 comments
Owner

Originally created by @gwkline on GitHub (Nov 29, 2023).
Original GitHub issue: https://github.com/hibiken/asynq/issues/790

Originally assigned to: @hibiken on GitHub.

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
)
Originally created by @gwkline on GitHub (Nov 29, 2023). Original GitHub issue: https://github.com/hibiken/asynq/issues/790 Originally assigned to: @hibiken on GitHub. **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 ) ```
kerem 2026-03-07 22:09:13 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@kamikazechaser commented on GitHub (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?

<!-- gh-comment-id:1843144832 --> @kamikazechaser commented on GitHub (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`?
Author
Owner

@kamikazechaser commented on GitHub (Dec 7, 2023):

Could you test https://github.com/hibiken/asynq/pull/796 and let me know if it fixes this issue.

cc/ @amaury1729

<!-- gh-comment-id:1844896035 --> @kamikazechaser commented on GitHub (Dec 7, 2023): Could you test https://github.com/hibiken/asynq/pull/796 and let me know if it fixes this issue. cc/ @amaury1729
Author
Owner

@gwkline commented on GitHub (Dec 7, 2023):

@kamikazechaser #796 does appear to solve this issue!

<!-- gh-comment-id:1845604877 --> @gwkline commented on GitHub (Dec 7, 2023): @kamikazechaser #796 does appear to solve this issue!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#1402
No description provided.