Redis3.2.1不设置密码影响的功能

Redis3.2.1不设置密码影响JedisPool获取链接

  • 和同事整合功能时发现,代码一致但是程序在我本地环境无法运行

  • 后来发现他的redis设置了密码,而我的默认没设置 疑惑:难道密码不设置会影响功能,抱着试试看的心理,设置了密码,发现能用了!

  • 整理一下这个坑。

1.问题场景:idea 2020.1、redis 3.2.1、操作系统:window(linux也同样要设置密码,否则设置)
package com.enjoylife.system.config;

import com.beust.jcommander.internal.Lists;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import org.springframework.data.redis.core.*;
import java.util.List;

@CommonsLog
@Configuration
@EnableCaching
public class RedisConfig extends CachingConfigurerSupport {
    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.password}")
    private String password;
    @Value("${spring.redis.port}")
    private int port;
    @Value("${spring.redis.timeout}")
    private int timeout;
    @Value("${spring.redis.pool.max-idle}")
    private int maxIdle;
    @Value("${spring.redis.pool.max-wait}")
    private long maxWaitMillis;
	//--- 以上配置文件内容没啥说的
	
    @Autowired(required = false)
    private RedisTemplate<String, Object> redisTemplate;
	//注入Bean
    @Bean
    public JedisPool redisPoolFactory() {
        log.info("JedisPool注入成功!!");
        log.info("redis地址:" + host + ":" + port);
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxIdle(maxIdle);
        jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);

        JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout,password);

        return jedisPool;
    }

}

//某个控制器某个方法中
public class MyController {
 	public void getSetValue(String value) {
        //获取jedis对象
		Jedis jedis =  redisManager.redisPoolFactory().getResource();
		//存入、取出需要用的数据
		jedis.set("key",value);
		String s = jedis.get("key");
    }
}

使用场景非常简单,就是的单纯的存取数据

2.解决办法:设置redis密码 【window下】
  1. 打开redis安装目录,找到redis.windows.conf、redis.windows-service.conf两个配置文件(可以都修改,也可以只修改第一个文件,主要看自己启动时用哪个文件)
    在这里插入图片描述
  2. 打开文件后,添加
# requirepass foobared
requirepass 你的密码
  1. 添加完文件后重启redis,启动命令 : redis-server.exe redis.windows.conf
    在这里插入图片描述
    OK!
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ywh22122

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值