in Education by
I am new to Redis and using Spring Boot + Spring Data Redis example. In this example, I used the QueryByExampleRedisExecutor on repository method and used the Example API to do the custom query. The following is the KEYS present in the Redis NoSQL DB. redis 127.0.0.1:6379> KEYS * 1) "country:76c78bcc-bb2a-41b3-a1fc-3dbb3042edd6:idx" 2) "country:76c78bcc-bb2a-41b3-a1fc-3dbb3042edd6" 3) "user:lastName:Kerr" 4) "user" 5) "user:role.roleName:API" 6) "country:countryName:India" 7) "Student:name:John Doe" 8) "user:8252a4b3-22a1-4e6c-99fc-04fed93a21a5:idx" 9) "user:8252a4b3-22a1-4e6c-99fc-04fed93a21a5" 10) "user:middleName:Lima" 11) "Student" 12) "user:middleName:Mike" 13) "user:firstName:John" 14) "country:countryCode:+91" 15) "user:role.roleName:ADMIN" 16) "user:lastName:Wixson" 17) "Student:1:idx" 18) "user:46ca0606-38a5-4d0c-8cea-38e2c4fa5bfa:idx" 19) "Student:2:idx" 20) "Student:1" 21) "user:firstName:Matt" 22) "user:46ca0606-38a5-4d0c-8cea-38e2c4fa5bfa" 23) "Student:2" 24) "country" 25) "Student:name:Michael Harford" 26) "country:84fc82f2-1c21-4d3e-9429-f1ee1039ceed:idx" 27) "country:84fc82f2-1c21-4d3e-9429-f1ee1039ceed" redis 127.0.0.1:6379> Repository method - Example example = Example.of(User.builder().firstName("Mike").build()); long count = userRepository.count(); System.out.println(count); When I execute the below method I was expecting to get only one result, but I am getting two count. Why ? More Info shown here: Consider revisiting the entries above or defining a bean of type 'org.springframework.data.redis.core.RedisTemplate' in your configuration How can we see the Redis snippet on the logs ? What configuration do I need to set ? public interface UserRepository extends CrudRepository, QueryByExampleExecutor{ List findByFirstName(String firstName); List findByFirstNameAndLastName(String firstName, String lastName); @Query("SELECT u FROM User u WHERE u.middleName LIKE :middleName ") List findCustomByMiddleName(@Param("middleName") String middleName); List findByRole_RoleName(String roleName); } Error below for reference - java.lang.IllegalStateException: Failed to execute CommandLineRunner at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:795) at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:776) at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) at com.baeldung.MainAppDemo.main(MainAppDemo.java:31) Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type User! at org.springframework.data.mapping.PropertyPath.(PropertyPath.java:94) at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358) at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:334) at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:287) at java.util.concurrent.ConcurrentMap.computeIfAbsent(Unknown Source) at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:269) at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:252) at org.springframework.data.repository.query.parser.Part.(Part.java:81) at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:250) at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source) at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source) at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source) at java.util.stream.AbstractPipeline.copyInto(Unknown Source) at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source) at java.util.stream.AbstractPipeline.evaluate(Unknown Source) at java.util.stream.ReferencePipeline.collect(Unknown Source) at org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:251) at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:380) at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source) at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source) at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source) at java.util.stream.AbstractPipeline.copyInto(Unknown Source) at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source) at java.util.stream.AbstractPipeline.evaluate(Unknown Source) at java.util.stream.ReferencePipeline.collect(Unknown Source) at org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:381) at org.springframework.data.repository.query.parser.PartTree.(PartTree.java:93) at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.createQuery(KeyValuePartTreeQuery.java:206) at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.prepareQuery(KeyValuePartTreeQuery.java:148) at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.execute(KeyValuePartTreeQuery.java:106) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:602) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:590) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) at com.sun.proxy.$Proxy69.findAll(Unknown Source) at com.baeldung.MainAppDemo.run(MainAppDemo.java:47) at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:792) ... 5 common frames omitted JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You are constructing an Example but then discard it by not using it. You are calling userRepository.count(); which basically counts all the records. You should be using the count that takes an Example. This method is on the QueryByExampleExecutor which your interface, UserRepository should extend as well. Then you can simply do. Example example = Example.of(User.builder().firstName("Mike").build()); long count = userRepository.count(example); System.out.println(count); And you should get the result you expected.

Related questions

0 votes
    I want have a setup of redis where I write to master and read from slave, without any sentinel. I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I have a GKE Cluster current scaled upto multiple nodes, the scale up happened during high load due to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    The transaction can no longer continue with its normal execution because of some internal condition, such ... topic in chapter Recovery System of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    The data type mapping between the database column and sqoop column can be overridden by using the parameter A - --override- ... - --override-column-java D - --map-column-java...
asked Jan 13, 2021 in Technology by JackTerrance
0 votes
    I followed these steps on https://github.com/karmi/tire to install elasticsearch for use with ruby on rails ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 30, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I'm trying to implement continuous integration and continuous deployment to my DEV Azure App Service. I'm ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I'm trying to install some machine learning libraries on a new Windows laptop (I usually have Mac laptops ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I'm trying to install some machine learning libraries on a new Windows laptop (I usually have Mac laptops ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I'm trying to install some machine learning libraries on a new Windows laptop (I usually have Mac laptops ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    Which of these clause will be executed even if no exceptions are found? (a) throws (b) finally (c) ... Exception Handling of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    I'm trying to deploy a Docker container image to AWS using ECS, but the EC2 instance is not being created. I have ... , to begin with!! Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Which of these clause will be executed even if no exceptions are found? (a) throws (b) finally (c ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    write a program in python to find the greatest of three no. given by user Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    What is User-Story Mapping?...
asked Nov 19, 2020 in Technology by Editorial Staff
...