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

Count and NoContent queries runs two queries on searchstream "close" invocation

Rohan-RPJ opened this issue · comments

Hi @bsbodden ,

I am trying to use EntityStream in multithreaded environment.

I am fetching SearchStream object from EntityStream, running the queries using collect/count methods and at last closing the searchstream object by close() method.

On calling close(), it executes the query once more.

I have couple of queries on above implementation:

  1. Is it required to call close on SearchStream, considering environment I am running in is multithreaded environment
  2. Are EntityStream and SearchStream objects thread safe to use in multithreaded environment

Please answer of above way is correct, if not then how do I use EntityStream in multithreaded environment

Thanks in advance!

Can you post an example of how you are using the EntityStream? It is for sure not a reentrant class, it's meant to be used as a session, and not reused. Just like a Java stream.

Posting example of my implementation.

@component
public class CacheClient { // singleton bean class

  @Autowired EntityStream entityStream; // used in multithreaded environment 

  public <E> long count(Class<E> entity class, SearchFieldPredicate<E, ?> predicate) {
        long count =0;
        try(SearchStream<E> ss = entityStream.of(entity class)) // autocloseable searchstream
        {
              ss.filter(predicate);
              count = ss.count(); // count query gets executed here
         } 
        // Searchstream close method gets called and one more query gets executed
        return count;
  }

}

  1. Is EntityStream object thread-safe ?
  2. Is the above implementation recommended approach when used in multithreaded environment ?

Please let me know your views on the above

Can you post an example of how you are using the EntityStream? It is for sure not a reentrant class, it's meant to be used as a session, and not reused. Just like a Java stream.

If EntityStream is not to be reused, then do I need to close EntityStream after each query and create new again for new queries ?

Can you post an example of how you are using the EntityStream? It is for sure not a reentrant class, it's meant to be used as a session, and not reused. Just like a Java stream.

If EntityStream is not to be reused, then do I need to close EntityStream after each query and create new again for new queries ?

Reuse of the EntityStream is not a problem, think of it as a factory, the SearchStream is what I meant shouldn't be reused. The extra query on close does not seem right, likely a bug. Thanks for reporting.

Can you post an example of how you are using the EntityStream? It is for sure not a reentrant class, it's meant to be used as a session, and not reused. Just like a Java stream.

If EntityStream is not to be reused, then do I need to close EntityStream after each query and create new again for new queries ?

Reuse of the EntityStream is not a problem, think of it as a factory, the SearchStream is what I meant shouldn't be reused. The extra query on close does not seem right, likely a bug. Thanks for reporting.

Ok got it. It means the code that I posted will work without any issues in multithreaded environment , right ?