Skip to content

Use FT._LIST in CreateAndAliasIndes#970

Open
yelly wants to merge 3 commits intoredis:mainfrom
yelly:list-create-alias-index
Open

Use FT._LIST in CreateAndAliasIndes#970
yelly wants to merge 3 commits intoredis:mainfrom
yelly:list-create-alias-index

Conversation

@yelly
Copy link
Copy Markdown

@yelly yelly commented Mar 15, 2026

Fixes #969.
The current implementation fails tests when running against Redis 8 (presumably the version in which the error message from FT.INFO changed).

Introduced a new implementation for CreateAndAliasIndex which does the following:

  1. Query FT._LIST.
  2. Finds all existing indexes which match the versioned index pattern (index + "_v" + version).
  3. Creates a new index with the latest version + 1 (or 1 if no existing index).
  4. Updates the alias to point to the new index (works whether or not the alias already exists).
  5. Drops all the old indexes.

The implementation is shared between Hash and JSON repositories to avoid duplication.
The new implementation passes the tests against Redis 8 and redis-stack.


Note

Medium Risk
Changes the RediSearch index migration/aliasing flow for both Hash and JSON repositories, including dropping all previously versioned indexes, which could impact deployments if index naming differs or drop semantics change. Risk is moderate and isolated to index management paths.

Overview
Fixes CreateAndAliasIndex for Redis 8 by replacing the FT.INFO/error-message-based alias detection with a shared implementation that uses FT._LIST to discover existing *_vN indexes.

Both HashRepository and JSONRepository now create the next versioned index, FT.ALIASUPDATE the alias to it, and then drop all prior versioned indexes via the new helper in om/indexes.go.

Reviewed by Cursor Bugbot for commit 1434867. Bugbot is set up for automated code reviews on this repo. Configure here.

@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented Mar 15, 2026

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates RediSearch index rotation in the om repositories to avoid fragile FT.INFO error-string parsing (which broke on Redis 8), by switching discovery to FT._LIST and centralizing the logic in a shared helper.

Changes:

  • Replaced per-repository CreateAndAliasIndex logic in HashRepository and JSONRepository with a shared createAndAliasIndex helper.
  • Implemented version discovery via FT._LIST, selecting the next idx_vN based on the max existing version and then dropping all prior versioned indexes.
  • Updated repositories to call the new helper and adjusted imports accordingly.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
om/indexes.go New shared helper implementing FT._LIST-based version selection, alias update, and cleanup of old versioned indexes.
om/hash.go Switched HashRepository.CreateAndAliasIndex to use the shared helper.
om/json.go Switched JSONRepository.CreateAndAliasIndex to use the shared helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread om/indexes.go
Comment on lines +44 to +63
newIndex := idx + "_v1"
if len(currVers) > 0 {
newIndex = fmt.Sprintf("%s_v%d", idx, slices.Max(currVers)+1)
}

// Create the new index
if err := client.Do(ctx, cmdFn(createCmd(newIndex).Schema())).Error(); err != nil {
return err
}

if err := client.Do(ctx, client.B().FtAliasupdate().Alias(idx).Index(newIndex).Build()).Error(); err != nil {
return fmt.Errorf("failed to update alias: %w", err)
}

for _, ver := range currVers {
currIdx := fmt.Sprintf("%s_v%d", idx, ver)
if err := client.Do(ctx, client.B().FtDropindex().Index(currIdx).Build()).Error(); err != nil {
return fmt.Errorf("failed to drop old index %q: %w", currIdx, err)
}
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flow can't be exercised using the OM alone so I'm conflicted about whether it's worth testing.

Comment thread om/indexes.go Outdated
Comment thread om/indexes.go Outdated
Comment thread om/indexes.go Outdated
@rueian
Copy link
Copy Markdown
Collaborator

rueian commented Mar 17, 2026

Hi @yelly, could you also add tests for Redis 8?

@rueian
Copy link
Copy Markdown
Collaborator

rueian commented Apr 7, 2026

ping @yelly, could you also add tests for Redis 8?

yelly and others added 2 commits April 16, 2026 13:36
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Also removed "failed" from wrapped errors as this results in error messages that say "failed" a lot.
@yelly
Copy link
Copy Markdown
Author

yelly commented Apr 23, 2026

ping @yelly, could you also add tests for Redis 8?

Hi sorry got pulled away from this for a bit.
How can I add Redis 8 tests? I'm not seeing any examples in the codebase for testing against other Redis versions apart from in rueidiscompat which doesn't seem relevant.
I've addressed some other comments raised by Copilot though.
@rueian

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

Successfully merging this pull request may close these issues.

Repository CreateAndAliasIndex matches missing index error too specifically

3 participants