Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
michaeltch opened this issue Jan 8, 2025 · 0 comments

Comments

@michaeltch
Copy link

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.

bitsark added a commit to bitsark/go-redis that referenced this issue Jan 9, 2025
* LOAD has NO AS param(https://redis.io/docs/latest/commands/ft.aggregate/)

* fix typo: WITHCOUT -> WITHCOUNT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant