redis操作问题

使用redisTemplate 往set集合中批量添加值

# 第一种办法就是for循环,每次进行set
	for (int i = 0; i < 1000000; i++) {
      redisTemplate.opsForSet().add("key",i);
  }
# 第二中办法就是使用HashSet批量添加数据
	Set set = new HashSet<>();
	for (int i = 1; i < 1000000; i++) {
      set.add(i);
	}
	redisTemplate.opsForSet().add("key",set.toArray());

redis整合spring版本的问题

具体原因
无法访问org.springframework.beans.factory.annotation.Autowired   
错误的类文件: org/springframework/spring-beans/6.0.9/spring-beans-6.0.9.jar!/org/springframework/beans/factory/annotation/Autowired.class     
类文件具有错误的版本 61.0, 应为 52.0     
请删除该文件或确保该文件位于正确的类路径子目录中。
解决办法
报错原因: SpringBoot使用了3.0或者3.0以上

# 因为Spring官方发布从Spring6以及SprinBoot3.0开始最低支持JDK17,所以仅需将SpringBoot版本降低为3.0以下即可。 解决方案: 将SpringBoot版本降低为3.0以下 版本随意,刷新Maven重启即可

redis报错redis.clients.jedis.JedisShardInfo.setTimeout(I)V

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisConnectionFactory' defined in class path resource [application-context.xml]: 
Invocation of init method failed; nested exception is
 java.lang.NoSuchMethodError: redis.clients.jedis.JedisShardInfo.setTimeout(I)V 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1
解决办法
# 错误原因,jedis客户端版本过高,

spring-data-redis用的1.4.2的版本 
jedis的版本号换成2.6.2以下就好了
具体操作
1. 打开网址 https://mvnrepository.com
2. 查看spring-data-redis对应的redis最低版本为多少(点击版本号进去看里面)
3. 修改pom文件中对应的版本号

image-20230709111605882

image-20230709112952824

redis报错(error) NOAUTH Authentication required

这个是因为redis客户端开启了密码,需要进行认证才能进入

在redis的conf文件中设置了密码。
打开redis.conf,可以找到如下内容,这个是要求验证用户,马赛克的地方就是要求输入的密码

在这里插入图片描述

解决办法
不输密码进入redis-cli后,单独在认证密码

在这里插入图片描述

redis序列化问题-invalid stream header

nested exception is java.io.StreamCorruptedException: invalid stream header: 00000000]
解决办法
在连接redis的时候加一个代码,就可以了
redisTemplate.setValueSerializer(new StringRedisSerializer());
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值