go-redis/redis · error

redis: non-string key at position %d: %v

Error message

redis: non-string key at position %d: %v

What it means

Error "redis: non-string key at position %d: %v" thrown in go-redis/redis.

Source

Thrown at osscluster_router.go:132

	args := cmd.Args()
	firstKeyPos := cmdFirstKeyPosWithInfo(cmd, c.cmdInfoPeek(cmd.Name()))
	stepCount := int(cmd.stepCount())
	if stepCount == 0 {
		stepCount = 1 // Default to 1 if not set
	}

	if firstKeyPos == 0 || firstKeyPos >= len(args) {
		return fmt.Errorf("redis: multi-shard command %s has no key arguments", cmd.Name())
	}

	// Group keys by slot
	slotMap := make(map[int][]string)
	keyOrder := make([]string, 0)

	for i := firstKeyPos; i < len(args); i += stepCount {
		key, ok := args[i].(string)
		if !ok {
			return fmt.Errorf("redis: non-string key at position %d: %v", i, args[i])
		}

		slot := hashtag.Slot(key)
		slotMap[slot] = append(slotMap[slot], key)
		for j := 1; j < stepCount; j++ {
			if i+j >= len(args) {
				break
			}
			slotMap[slot] = append(slotMap[slot], args[i+j].(string))
		}
		keyOrder = append(keyOrder, key)
	}

	return c.executeMultiSlot(ctx, cmd, slotMap, keyOrder, policy, firstKeyPos)
}

// executeMultiSlot executes commands across multiple slots concurrently
func (c *ClusterClient) executeMultiSlot(ctx context.Context, cmd Cmder, slotMap map[int][]string, keyOrder []string, policy *routing.CommandPolicy, firstKeyPos int) error {

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Pass string keys to multi-shard commands; the position in the error shows the offending argument
  2. Convert key arguments to strings before building the command

When it happens

Trigger: Thrown at osscluster_router.go:132 when the library encounters an invalid state.

Common situations: Type-check key arguments at command construction.


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