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

Ability to modify/filter the ID portion of the Key (Redis Cluster Hashtags) #454

Closed
bsbodden opened this issue Jun 6, 2024 · 0 comments
Closed
Assignees

Comments

@bsbodden
Copy link
Contributor

bsbodden commented Jun 6, 2024

Redis Cluster implements a concept called hash tags that can be used to force certain keys to be stored in the same hash slot. However, during manual resharding, multi-key operations may become unavailable for some time while single-key operations are always available.

Using the @IdFilter one can provide a class that can transform the ID portion of the Redis Key:

@Document("dwht")
public class DocWithHashTagId {
    @Id
    @IdFilter(value = IdAsHashTag.class)
    private String id;

    @Indexed
    @NonNull
    private String name;
}

One simple implementation of the IdentifierFilter interface is provided as shown above IdAsHashTag:

public class IdAsHashTag implements IdentifierFilter<Object> {
    @Override
    public String filter(Object id) {
        return "{" + id.toString() + "}";
    }
}

Which adds { and } around the ID portion of the key, int he case above keys will look like:

"dwht:{01HZQGRZ2JC5YR3W18CGQM6RP4}"
@bsbodden bsbodden self-assigned this Jun 6, 2024
bsbodden added a commit to bsbodden/redis-om-spring that referenced this issue Jun 6, 2024
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