分布式锁NOAUTH Authentication required..

增加redis分布式锁 开发环境没问题

测试环境报错

{"code":500,"message":"未知错误,请联系管理员!","result":"NOAUTH Authentication required.. channel: [id: 0xf797c42b, L:/172.17.251.224:45770 - R:/172.17.251.230:6393] command: CommandData [promise=org.redisson.misc.RedissonPromise@7d7e40fc[Not completed], command=(EVAL), params=[if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;..., 2, AppointmentStuLock283890940019589120, redisson_lock__channel:{AppointmentStuLock283890940019589120}, 0, 30000, 36288b45-3aab-4de8-913d-7f91fe3c51e2:75], codec=org.redisson.client.codec.LongCodec@57070e1a]"}
NOAUTH Authentication required..

没有权限访问数据库,原来是使用Redisson忘记将密码设置进Redisson的config配置文件里了,可能你会说我在yml或者properties配置文件中配置了redis的相关信息,但Redisson是不会去加载的。

解决方法

redisson 设置密码

 

@Configuration
public class RedissonConfig {

    /**
     * 获取redis地址
     */
    @Value("${spring.redis.host}")
    private String redisHost;

    /**
     * 获取redis端口
     */
    @Value("${spring.redis.port}")
    private String redisPort;

    /**
     * 获取redis密码  获取不到默认为空字符串
     * @return
     */
    @Value("${spring.redis.password:}")
    private String password;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + redisHost + ":" + redisPort);
        if(password!=null && !"".equals(password)){
            config.useSingleServer().setPassword(password);
        }
        RedissonClient client = Redisson.create(config);
        return client;
    }
}

 

 

 

 
posted @ 2023-03-14 10:17  mcdullcode  阅读(367)  评论(0)    收藏  举报