Skip to content

When using Resp 2 FTAggregateWithArgs does not return an error when using the "as" option #3220

Closed
@michaeltch

Description

@michaeltch

I have provided an example program that doesn't panic when the command run on the database should return an error.

Expected Behavior

Panic with error message (error) Unknown argument AS at position 4 for <main>

Current Behavior

The resulting pointer is nil and error is empty causing no panic.
result: 0x0

Steps to Reproduce

package main

import (
	"context"
	"strings"

	"github.com/redis/go-redis/v9"
)

func createIndexAndLoadData(client *redis.Client, ctx context.Context) {
	if _, err := client.FTCreate(ctx,
		"temp",
		&redis.FTCreateOptions{Prefix: []interface{}{"user:"}},
		&redis.FieldSchema{FieldName: "__key", FieldType: redis.SearchFieldTypeText},
	).Result(); err != nil && !strings.Contains(err.Error(), "Index already exists") {
		panic(err)
	}

	if _, err := client.HSet(ctx, "user:1", []string{"__key", "v1"}).Result(); err != nil {
		panic(err)
	}
}

func runAggregateQuery(client *redis.Client, ctx context.Context) {
	filterOpts := &redis.FTAggregateOptions{
		Load: []redis.FTAggregateLoad{
			{
				Field: "@__key",
				As:    "key",
			},
		},
	}
	result, err := client.FTAggregateWithArgs(ctx, "temp", "*", filterOpts).Result()
	if err != nil {
		panic(err)
	}
	println("result:", result)
}

func main() {
	ctx := context.Background()
	client := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Protocol: 2,
	})

	createIndexAndLoadData(client, ctx)

	runAggregateQuery(client, ctx)
}

Removing the As field fixes the issue and a proper response is returned.

Context (Environment)

Attempting to recreate a separate issue. The database is OSS 6.2.7.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions