Home » Java » java – Spring Data Redis search in collection-Exceptionshub

java – Spring Data Redis search in collection-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

Let’s imagine I’ve got entity like

@RedisHash(value = "Question",timeToLive = -1)
@Data
public class Question {

private String id;
@Indexed private String question;
@Indexed private String indexName;
@Indexed  List<Long> folderIds;
List<Answer> answers;

The scenarios to get this entity from redis will be the following
1. Search by question, indexName and exact match of folderIds list.
2. Search by indexName and specific folderId in this folderIds list.

As I understand – Spring Data Redis doesn’t support IN, CONTAINS and all other stuff to search in collection. So my first idea was to store folderIds as string (in presorted order and joined with comma separator). This will help in first scenario. But for second scenario it won’t work, cause LIKE operation is also not supported in Repository. And only way i see here – grab everything by indexName and then filter this large collection manually, but it looks like not very performance friendly.

Maybe I’m missing something and there is some good way to deal with such case.
Thanks!

How to&Answers: