go-redis/redis · error

invalid key type at index %d

Error message

invalid key type at index %d

What it means

Raised in parseFTHybrid (search_commands.go:3040-3045) when reading FTHybrid (FT.HYBRID? — the FT.HYBRID family) replies as flat key/value pairs: the element at even index must be a string key. A non-string at that position means the reply stream is malformed.

Source

Thrown at search_commands.go:3044

func (cmd *FTHybridCmd) RawVal() interface{} {
	cmd.await()
	return cmd.rawVal
}

func (cmd *FTHybridCmd) RawResult() (interface{}, error) {
	cmd.await()
	return cmd.rawVal, cmd.err
}

func parseFTHybrid(data []interface{}, withCursor bool) (FTHybridResult, *FTHybridCursorResult, error) {
	// Convert to map
	resultMap := make(map[string]interface{})
	for i := 0; i < len(data); i += 2 {
		if i+1 < len(data) {
			key, ok := data[i].(string)
			if !ok {
				return FTHybridResult{}, nil, fmt.Errorf("invalid key type at index %d", i)
			}
			resultMap[key] = data[i+1]
		}
	}

	// Handle cursor result
	if withCursor {
		searchCursorID, ok1 := resultMap["SEARCH"].(int64)
		vsimCursorID, ok2 := resultMap["VSIM"].(int64)
		if !ok1 || !ok2 {
			return FTHybridResult{}, nil, fmt.Errorf("invalid cursor result format")
		}
		return FTHybridResult{}, &FTHybridCursorResult{
			SearchCursorID: int(searchCursorID),
			VsimCursorID:   int(vsimCursorID),
		}, nil
	}

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Inspect cmd.RawVal() / RawResult() to see the actual array contents.
  2. Confirm you are calling FTHybrid against a server that supports it.
  3. Upgrade go-redis and the server module to matched versions.
  4. Reproduce via redis-cli.
Defensive patterns

Strategy: try-catch

Try / catch

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

Prevention

When it happens

Trigger: Calling FTHybrid / FTHybridWithArgs and the server returned a flat array whose even-position entries are not strings — typically because the reply is actually a different shape (e.g. nested array or map).

Common situations: Version skew between go-redis and the Redis server's hybrid search module, or a reply that wrapped the pairs in an extra level.

Related errors


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