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

Create Indexes using single class and multiple Configuration #332

Open
rpjtesting opened this issue Aug 21, 2023 · 7 comments
Open

Create Indexes using single class and multiple Configuration #332

rpjtesting opened this issue Aug 21, 2023 · 7 comments
Assignees

Comments

@rpjtesting
Copy link

rpjtesting commented Aug 21, 2023

Hi there,

I have a single class called RedisEntityClass having following fields present:

class RedisEntityClass {
String field1;
String field2:
String field3;
}

With below cache configurations:
Cache1:
field1: val11
field2: val12
field3: val13

Cache2:
field1: val21
field2: val22
field3: val23

.. and so on.

I need to create Json Documents for all above caches using single Java Class as the structure for all the caches is same, hence I don't want to create similar Java classes as well for all the cache configurations.

I think it can work by creating a class for each cache with different names and extend to RedisEntityClass like below:

@document("cache1:")
class Cache1 extends RedisEntityClass {}
@document("cache2:")
class Cache2 extends RedisEntityClass {}
.... and so on.

This may work, but I have thousands of such caches and I don't want to create empty classes for each cache like this.

Is it possible to provide a feature in RedisOM-Spring library which will take input the above config data, map it to single entity class like RedisEntityClass, and create indexes for all the caches at once.

Currently I have copied the library code and tweaked a little to meet the requirements, but I know this is not the good approach in long run :(

Please help me with this :)

@bsbodden
Copy link
Contributor

@rpjtesting let me think about this use case and whether it makes sense to implement it. Cheers.

@bsbodden bsbodden self-assigned this Aug 24, 2023
@bsbodden
Copy link
Contributor

bsbodden commented Sep 2, 2023

There a few issues to be resolve for this to be doable:

  1. Repositories: are bound to a given class by design - I don't see a feasible way to make them work against multiple classes
  2. EntityStreams are also bound to a given class also - this could be handled with a method but you still have no way to save the entities

I did some research on inheritance in Spring Data and JPA and I imagine the complications with the repositories API prevent something like this from being implemented. Can you share your changes to see what you did? I still think the repositories API is a no go.

@bsbodden bsbodden closed this as completed Sep 4, 2023
@rpjtesting
Copy link
Author

@bsbodden I can't share code due to some restrictions. But I think this is possible and I have implemented it by tweaking the library code and it's working.

But changing the lib code and using it deprives us from taking latest changes at same pace.

Please rethink on this, and if any other ways to solve this then suggestions are welcome!

@rpjtesting
Copy link
Author

There a few issues to be resolve for this to be doable:

  1. Repositories: are bound to a given class by design - I don't see a feasible way to make them work against multiple classes
  2. EntityStreams are also bound to a given class also - this could be handled with a method but you still have no way to save the entities

I did some research on inheritance in Spring Data and JPA and I imagine the complications with the repositories API prevent something like this from being implemented. Can you share your changes to see what you did? I still think the repositories API is a no go.

Is there a way to create indexes for entities without need to create a class or repository, just use the single class as a reference for all the entities, that solves my problem. Jedis might be one solution but redis om has that built in, just need to expose some methods ;)

@bsbodden
Copy link
Contributor

@rpjtesting are you up for a exploratory PR for this?

@bsbodden bsbodden reopened this Sep 14, 2023
@rpjtesting
Copy link
Author

@bsbodden sure but will require sometime as I dont have it in my personal machine. But if possible, I will try to explain the changes I made and in which classes.

  1. In previous redisom version, in class RedisModulesConfiguration, if I am not wrong, there was a method ensureIndexesCreated(...) something like that by taking applicationCtx as input and searched for all model classes having @Document/@RedisHash annotations and created indexes for those classes, which is now part of RedisSearchIndexer in latest om version.

  2. The cache name was fetched based on the value provided in annotation or it is classpath if value is empty.

  3. Our requirement is to create indexes where instead of searching for classes with annotations, I would pass the cache name (or list of cache names) and an entity class to which that cache should map to. Rest of the code could be same.

  4. The other requirement is datatypes of all variables present in entity class will be Java.lang.Object and I need to provide Redis Datatypes(like tag, text, numeric etc.) at runtime per cache.

Let me know if this is possible or creating custom implementation is better

@bsbodden
Copy link
Contributor

bsbodden commented Oct 2, 2023

3. here instead of searching for classes with annotations, I would pass the cache name (or list of cache names) and an entity class to which that cache should map to. Rest of the code could be same

I've consulting with the other OM implementers, and of course, in Java/Spring this a little bit harder to pull off. I think the we can start by opening the index creation with an API that can make it simpler for you rather that using Jedis directly. I need to experiment with a concrete example. Can you provide a (broken) sample with some dummy Entities and a basic usage? If I can hack it work correctly then we can see how we can provide a clean API for it.

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

2 participants