Skip to content

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

@bsbodden

Description

@bsbodden
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}"

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions