go-redis/redis · error

too many arguments

Error message

too many arguments

What it means

Set on the returned *ZSliceCmd when ZPopMax is called with more than one count argument. The variadic count parameter is meant to be empty (default 1) or a single int64; passing two or more values is ambiguous and rejected client-side before contacting Redis.

Source

Thrown at sortedset_commands.go:318

	cmd := NewFloatSliceCmd(ctx, args...)
	_ = c(ctx, cmd)
	return cmd
}

func (c cmdable) ZPopMax(ctx context.Context, key string, count ...int64) *ZSliceCmd {
	args := []interface{}{
		"zpopmax",
		key,
	}

	switch len(count) {
	case 0:
		break
	case 1:
		args = append(args, count[0])
	default:
		cmd := NewZSliceCmd(ctx)
		cmd.SetErr(errors.New("too many arguments"))
		return cmd
	}

	cmd := NewZSliceCmd(ctx, args...)
	_ = c(ctx, cmd)
	return cmd
}

func (c cmdable) ZPopMin(ctx context.Context, key string, count ...int64) *ZSliceCmd {
	args := []interface{}{
		"zpopmin",
		key,
	}

	switch len(count) {
	case 0:
		break
	case 1:

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Pass at most one count argument: ZPopMax(ctx, key) or ZPopMax(ctx, key, n).
  2. If using a slice, extract only the first element: ZPopMax(ctx, key, counts[0]).
  3. Validate len(count) <= 1 before the call.

Example fix

// before
client.ZPopMax(ctx, key, 1, 2) // too many counts

// after — single count or none
client.ZPopMax(ctx, key, 2)
// or default of 1
client.ZPopMax(ctx, key)
Defensive patterns

Strategy: validation

Validate before calling

func zpopMax(ctx context.Context, c *redis.Client, key string, count ...int64) *redis.ZSliceCmd {
    if len(count) > 1 {
        panic("ZPopMax accepts at most one count argument")
    }
    return c.ZPopMax(ctx, key, count...)
}

Try / catch

cmd := c.ZPopMax(ctx, key, counts...)
if err := cmd.Err(); err != nil && err.Error() == "too many arguments" {
    // too many counts; retry with at most one
}

Prevention

When it happens

Trigger: Calling ZPopMax(ctx, key, 1, 2) or spreading a slice with >1 element into count (ZPopMax(ctx, key, counts...) where len(counts) > 1). The default case 0 (pop 1) and case 1 (explicit count) are the only valid arities.

Common situations: Spreading a dynamic slice into the variadic count without checking its length. Copy-paste from APIs that accept multiple counts. Mistaking the variadic signature for accepting min/max bounds.

Related errors


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /data/errors/59588a6e7f7907a8.json. Report an issue: GitHub.