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

Executing full-text queries by using Redis template #2908

Open
dasivon021 opened this issue May 16, 2024 · 4 comments
Open

Executing full-text queries by using Redis template #2908

dasivon021 opened this issue May 16, 2024 · 4 comments
Labels
for: team-attention An issue we need to discuss as a team to make progress status: waiting-for-triage An issue we've not yet triaged

Comments

@dasivon021
Copy link

Hi,

Context:

I have a Spring Boot 3.2.3 app which uses spring-boot-starter-data-redis. We have a Redis cluster on the cloud, where RediSearch module is installed and where other applications are doing inserts of hash records. My application will only be executing search queries and have read-only permission towards cluster. So index already exist and I need to find a way to use it within my full-text queries but relaying on spring-boot-starter-data-redis since redis-om-spring has currently few issues which are blocking usage of pre-created index (#437, #438 & #439).

So pre-created index is created like this:

"FT.CREATE" "company:idx" "ON" "HASH" "PREFIX" "1" "session:" "SCHEMA" "User-Name" "TAG" "SEPARATOR" "|" "Event-Timestamp" "NUMERIC" "SORTABLE"

  1. Using Jedis (by excluding it from starter and adding jedis to pom):

Defining a template:

  @Bean
    public RedisTemplate<Long, Student> redisTemplate(RedisConnectionFactory connectionFactory) {
        var template = new RedisTemplate<Long, Student>();
        template.setConnectionFactory(connectionFactory);
        template.setEnableTransactionSupport(true);
        return template;
    }

Using it:

@GetMapping("/get")
public String getEntity(){
  Object o = executeCommand("FT.SEARCH", "comapany:idx".getBytes(), "@User\\-Name{pera}".getBytes(), "SORTBY".getBytes(), "Event-Timestamp".getBytes(), "DESC".getBytes(), "LIMIT".getBytes(), "0".getBytes(), "1".getBytes());
               
  System.out.println(o);
  return "a";
}

public Object executeCommand(String command, byte[]... parts) {
  return redisTemplate.execute(connection ->
	connection.execute(command, parts), false
  );
}

If I were to execute above query in redis-cli, the output would be:

1) (integer) 1
2) "student:abc"
3)  1) "User-Name""
    2) "pera"
     ..key-value pairs

But in code I get a List with bytes, which I don't like and there could be potential performance issues when doing (de)serialization. The problem with connection.execute is that returns byte[]
Screenshot_12

Question 1:
Is there a more optimal way to do issue these types of queries?

Question 2:
Is there a way to configure Redis template so when it issues these types of queries to return a list of entities instead of raw bytes?

  1. Using Lettuce (starter default):
java.lang.UnsupportedOperationException: io.lettuce.core.output.ByteArrayOutput does not support set(long)
	at io.lettuce.core.output.CommandOutput.set(CommandOutput.java:107) ~[lettuce-core-6.3.1.RELEASE.jar:6.3.1.RELEASE/12e6995]
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 16, 2024
@dasivon021
Copy link
Author

Hi @mp911de Your assistance is needed :)

@mp911de
Copy link
Member

mp911de commented May 16, 2024

There's no need to ping individual contributors and create further distraction. We see incoming tickets and once we have time, we will get to these.

@mp911de
Copy link
Member

mp911de commented May 21, 2024

Spring Data can run arbitrary commands against Redis; however, because Spring Data isn't aware of the command response structure, it can only pass on results from the driver in their raw form.

For Lettuce, you can implement your own CommandOutput and pass it on to LettuceConnection.execute(String, CommandOutput, byte[]...).

@jone-code
Copy link

Same problem +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: team-attention An issue we need to discuss as a team to make progress status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

4 participants