redis / redis-om-spring

Spring Data Redis extensions for better search, documents models, and more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@Document (JSON) and String[] prefixes - Override is not working as expected.

gacerioni opened this issue · comments

Howdy, guys!

I am trying to show (value) that RDI will not add much impedance and will not make the Developers suffer when they stop reading data from MySQL or PostgreSQL.

My initial honest guess is to use Redis Spring OM to automatically map some Models and ensure that the indexing works for both data: the one that comes from the Controller CRUD + the equivalent stuff from RDI.

Everything is really easy and works like a charm, but I would need to override the way the index is created (automatically) by Redis Spring OM.
I have data denormalization, so I can't really perform Key expressions (with RDI). This is a known limitation, explored here.

So... I decided to try to override the prefixes of that index just to make sure I could work around this limitation since I can't really change the key naming to match the one from RDI.

I tried to do this, with @Document(prefixes:

<...>
@RequiredArgsConstructor(staticName = "of")
@Data
@TypeAlias("PersonRedis")
@Document(prefixes = {"io.platformengineer.rdicpfhighvolume.person.PersonRedis:", "person:"})
//@Document(prefixes = {"person:"})
public class PersonRedis {

    @Id
    @NonNull
    private Long cpf; // Use CPF as the ID

    @NonNull
    @Searchable
    private String first_name;
<...>

But it did not work as expected. The prefix is always io.platformengineer.rdicpfhighvolume.person.PersonRedis:
This was an honest noob move, and I am not sure that @document is the exact place to do it.

@gacerioni prefixes in @Document was a early idea that's not implemented. Likely having multiple prefixes for a Entity class index might prove to create more issues that it solves. Neither does @TypeAlias. To customize the prefix your can simply do @Document("myPrefix") and you get myPrefix:XXX

Thank you very much, sir!
I believe we'll do a great demo, because APM (DataDog) will show the latency drop as soon as I start reading from Redis instead of MySQL (RDS).

Thanks!!!

@bsbodden, this is the best outcome I could ever imagine.
It's working! Automatically, Indexing both models (MySQL RDI and Spring OM)

You are a rockstar!
This is with RDI denormalizing a 1-N relationship, where a Person could have 0-n cars.

image