Conversation
|
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. |
There was a problem hiding this comment.
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
CreateAndAliasIndexlogic inHashRepositoryandJSONRepositorywith a sharedcreateAndAliasIndexhelper. - Implemented version discovery via
FT._LIST, selecting the nextidx_vNbased 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.
| 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) | ||
| } | ||
| } |
| for _, message := range listResp { | ||
| n, err := message.ToString() | ||
| if err != nil { | ||
| return fmt.Errorf("FT._LIST retured non-string response: %w", err) |
|
|
||
| // Create the new index | ||
| if err := client.Do(ctx, cmdFn(createCmd(newIndex).Schema())).Error(); err != nil { | ||
| return err |
|
Hi @yelly, could you also add tests for Redis 8? |
|
ping @yelly, could you also add tests for Redis 8? |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Fixes #969.
The current implementation fails tests when running against Redis 8 (presumably the version in which the error message from
FT.INFOchanged).Introduced a new implementation for
CreateAndAliasIndexwhich does the following:FT._LIST.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
Touches RediSearch index lifecycle management (create/alias/drop), so mistakes could break search availability or delete the wrong indexes; scope is limited to
CreateAndAliasIndexlogic.Overview
Fixes
CreateAndAliasIndexfor both hash and JSON repositories by switching fromFT.INFOerror-string parsing toFT._LIST-based discovery of existing*_vNindexes.The new shared helper (
om/indexes.go) computes the next versioned index name, creates it, repoints the alias withFT.ALIASUPDATE, and then drops all previously versioned indexes, reducing duplication betweenHashRepositoryandJSONRepository.Reviewed by Cursor Bugbot for commit f749add. Bugbot is set up for automated code reviews on this repo. Configure here.