go-redis/redis · error

invalid item key format

Error message

invalid item key format

What it means

Raised in the RESP2-style fallback path of parseFTHybrid (search_commands.go:3102-3107): when a result item is parsed as a flat key/value array, even-index elements must be string keys.

Source

Thrown at search_commands.go:3106

					itemMap[keyStr] = v
				}
			}
			results = append(results, itemMap)
			continue
		}

		// Fall back to array format (RESP2 format - key-value pairs)
		itemData, ok := item.([]interface{})
		if !ok {
			return FTHybridResult{}, nil, fmt.Errorf("invalid result item format")
		}

		itemMap := make(map[string]interface{})
		for i := 0; i < len(itemData); i += 2 {
			if i+1 < len(itemData) {
				key, ok := itemData[i].(string)
				if !ok {
					return FTHybridResult{}, nil, fmt.Errorf("invalid item key format")
				}
				itemMap[key] = itemData[i+1]
			}
		}
		results = append(results, itemMap)
	}

	// Optional warnings; accept both "warning" (as FT.SEARCH/FT.AGGREGATE) and "warnings".
	var warnings []string
	warningsData, ok := resultMap["warning"].([]interface{})
	if !ok {
		warningsData, ok = resultMap["warnings"].([]interface{})
	}
	if ok {
		warnings = make([]string, 0, len(warningsData))
		for _, w := range warningsData {
			if ws, ok := w.(string); ok {
				warnings = append(warnings, ws)

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Inspect RawResult() to find the failing pair index.
  2. Upgrade server module and go-redis.
  3. Reproduce via redis-cli.
  4. File an issue with the raw payload.
Defensive patterns

Strategy: try-catch

Try / catch

res, _, err := client.FTHybridWithArgs(ctx, idx, opts).Result()
if err != nil && strings.Contains(err.Error(), "invalid item key format") {
    raw, _ := cmd.RawVal()
    log.Printf("fthybrid item key not string; raw=%#v", raw)
}

Prevention

When it happens

Trigger: A result item parsed as an array contains a non-string at an even index, indicating the pairs stream is corrupt or misaligned.

Common situations: Server-side variant emitting non-string keys, or reply corruption over an unstable connection.

Related errors


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