Redis Query-by-Example supports only case-sensitive matching

engourdi engourdi 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
用springboot整合redis和jpa爆的错,数据库mysql
配置
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xx?useunicode=true&characterEncoding=utf8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=xx
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.max-idle=60
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5
# Specify the DBMS
spring.jpa.database = MYSQL
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = none
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# stripped before adding them to the entity manager
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.main.allow-bean-definition-overriding=true
# \load all-endpoint/ default info / health
management.endpoints.web.exposure.include=*
#redis
spring.redis.host=127.0.0.1
spring.redis.password=xx
spring.redis.lettuce.pool.maxActive=5
spring.redis.lettuce.pool.maxIdle=5


代码:

public interface MyRedisUserRepository extends CrudRepository<User, Long>{
Optional<User> findOneByPhone(String phone);
//Optional<User> findOneByEmail(String email);
}

public interface MysqlUserRepository extends JpaRepository<User, Long>{

}
@Slf4j
@Service
@Transactional
public class UserService {
@Autowired
MysqlUserRepository mysqlUserRepository;
@Autowired
MyRedisUserRepository myRedisUserRepository;
public Optional<User> findUserByPhone(String phone){
Optional<User> catched = myRedisUserRepository.findOneByPhone(phone);
if(catched.isPresent()) {
User user = catched.get();
log.info("user {} found in cache.",user);
return Optional.of(user);
}else {
Optional<User> raw = findOneUserByPhone(phone);
raw.ifPresent(c->{
myRedisUserRepository.save(c);
});
return raw;
}
}
public Optional<User> findOneUserByPhone(String phone){
ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("phone", exact().ignoreCase());
Optional<User> user = mysqlUserRepository.findOne(Example.of(User.builder().phone(phone).build(),matcher));
log.info("user found in sql:{}",user);
return user;
}
public Optional<User> saveUser2Sql(User user){
user = mysqlUserRepository.save(user);
return Optional.of(user);
}
}
@SpringBootApplication
@Slf4j
@EnableJpaRepositories
@EnableRedisRepositories
public class MybootApplication implements ApplicationRunner{
@Autowired
private UserService userService;
public static void main(String[] args) {
SpringApplication.run(MybootApplication.class, args);
}

@Override
public void run(ApplicationArguments args) throws Exception {
// Optional<User> u = userService.findUserByPhone("xxxx");
// log.info("user {}",u);
// userService.findAllUser();
User user = User.builder().phone("xxxxx").name("xx").city("xx").email("xx@126.com").build();
// userService.saveUser(user);
// userService.findUserByPhone("xxx");
log.info("user {}",user);
userService.saveUser2Sql(user);
log.info("user {}",user);
log.info("user {}",userService.findOneUserByPhone("xxxx").get());
//userService.findUserByEmail("engourdi@126.com");
}

}

@Entity
@Builder
@RedisHash(value = "myboot-user", timeToLive = 2592000)
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "user")
public @Data class User implements Serializable{
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
private Integer id;
private String name;
private String phone;
private String email;
private String password;
}

异常日志:

java.lang.IllegalStateException: Failed to execute ApplicationRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:807) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:794) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:324) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at com.franklin.myboot.MybootApplication.main(MybootApplication.java:28) [classes/:na]
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Redis Query-by-Example supports only case-sensitive matching.
at org.springframework.data.redis.repository.query.ExampleQueryMapper.applyPropertySpec(ExampleQueryMapper.java:137) ~[spring-data-redis-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.redis.repository.query.ExampleQueryMapper.lambda$applyPropertySpecs$0(ExampleQueryMapper.java:118) ~[spring-data-redis-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at java.lang.Iterable.forEach(Unknown Source) ~[na:1.8.0_161]
at org.springframework.data.redis.repository.query.ExampleQueryMapper.applyPropertySpecs(ExampleQueryMapper.java:106) ~[spring-data-redis-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.redis.repository.query.ExampleQueryMapper.getMappedExample(ExampleQueryMapper.java:88) ~[spring-data-redis-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.redis.repository.support.QueryByExampleRedisExecutor.createQuery(QueryByExampleRedisExecutor.java:187) ~[spring-data-redis-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.redis.repository.support.QueryByExampleRedisExecutor.findOne(QueryByExampleRedisExecutor.java:97) ~[spring-data-redis-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_161]
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at com.sun.proxy.$Proxy113.findOne(Unknown Source) ~[na:na]
at com.franklin.myboot.service.UserService.findOneUserByPhone(UserService.java:55) ~[classes/:na]
at com.franklin.myboot.service.UserService$$FastClassBySpringCGLIB$$322924e3.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) ~[spring-tx-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.spri
...全文

相关推荐

tft-query:使用内置的Redis缓存查询Riot的TFT数据的工具

tft查询 与Riot的TFT Api交互的接口。 支持本地Redis缓存。 如何安装: npm i tft-query 基本开始 const TftQuery = require ( 'tft-query' ) ; const payload = { summonerName : 'scarra' } ; const region = 'NA' ; const config = { region , /* <String> */ payload , /* &lt;Object&gt; See documentation for more info */ yourApiKey , /* by default it will be process.env.API_KEY */ useRedis ,

铭哲友野

php结合redis实现高并发下的抢购、秒杀功能的实例

下面小编就为大家带来一篇php结合redis实现高并发下的抢购、秒杀功能的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

weixin_38507923

redis数据库

redis简单入门,包括基本的redis简介,也包含redis五大类型介绍

baililanxue

使用 Redis 缓存您的 Mongoose MongoDB 查询结果 查询速度提高 300%!.zip

使用 Redis 缓存您的 Mongoose MongoDB 查询结果。查询速度提高 300%!mongoose-redis 缓存用于在 Redis 中缓存 Mongoose MongoDB 查询结果的插件。精益数据库查询,速度至少提高 300%!2014 年 5 月 30 日 - 关于此项目的说明抱歉各位,我没有来维护这个项目!这个项目没有得到积极的维护,对此我深感抱歉。我很希望有人能积极参与这个项目,如果你感兴趣的话请给我发邮件conancat@gmail.com,我们会想办法解决的!非常感谢你们!如何使用首先,通常npm install mongoose-redis-cache然后,Setup mongoose connect as usual: var mongoose = require("mongoose"); var mongooseRedisCache = require("mongoose-redis-cache"); mongoose.connect("mongodb://localhost/mongoos

徐浪老师

Go开发基于gw+redis解决Prometheus重查询问题源码.zip

【项目介绍】 Go开发基于gw+redis解决Prometheus重查询问题源码.zipGo开发基于gw+redis解决Prometheus重查询问题源码.zipGo开发基于gw+redis解决Prometheus重查询问题源码.zipGo开发基于gw+redis解决Prometheus重查询问题源码.zipGo开发基于gw+redis解决Prometheus重查询问题源码.zipGo开发基于gw+redis解决Prometheus重查询问题源码.zipGo开发基于gw+redis解决Prometheus重查询问题源码.zip Go开发基于gw+redis解决Prometheus重查询问题源码.zip 【备注】 1.项目代码均经过功能验证,确保稳定可靠运行。欢迎下载食用体验! 2.主要针对各个计算机相关专业,包括计算机科学、信息安全、数据科学与大数据技术、人工智能、通信、物联网等领域的在校学生、专业教师、企业员工。 3.项目具有丰富的拓展空间,不仅可作为入门进阶,也可作为毕设、课程设计、大作业、初期项目立项演示等用途。 4.鼓励大家基于此进行二次开发。在使用过程中,如有问题或建议,请及时沟通。 5.期待你能在项目中找到乐趣和灵感,也欢迎你的分享和反馈!

.whl
评论 1
收藏 已收藏
分享
返回顶部
engourdi
Java EE 67,535 成员 225,843 内容