skip to Main Content

I have found this Error:

ERR wrong number of arguments for 'zadd' command in golang.

This is my code:

defaultPriority:type String
mb.MessageID:type string
mb.EndpointID: type string

    _, err = mbDal.redisClient.ZAdd(mb.EndpointID, redis.Z{Score: defaultPriority, Member: mb.MessageID})
        if err != nil {
            return fmt.Errorf("failed to add mailbox id %s in redis; error %v", mb.MessageID, err)
        }

How can I fix this error message?

2

Answers


  1. zadd is used in go-redis/redis, and is defined here

    // Redis `ZADD key score member [score member ...]` command.
    func (c cmdable) ZAdd(key string, members ...*Z) *IntCmd {
    

    Double-check your go.mod dependencies list.
    10 months ago, in go-redis v7 (instead of current v8), the signature for that function was:

     func (c *cmdable) ZAdd(key string, members ...Z) *IntCmd {
    

    It used Z instead of (today) *Z.

    In your case, you should pass:

    &redis.Z{Score: defaultPriority, Member: mb.MessageID}
    
    Login or Signup to reply.
  2. I was trying to insert redis.Z{Score: [an int value], Member: code} to Redis sorted set and it failed with that error.

    So I checked my logic and find out someone calling my method with code as an empty string. in my case first insert was successful but after that, all insert failed with that error.

    • I’m using github.com/go-redis/redis v6.15.6
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search