当前位置:   article > 正文

Redis解决方案:NOAUTH Authentication required(连接jedis绑定密码或修改redis密码)_jedis noauth authentication required

jedis noauth authentication required

Redis解决方案:NOAUTH Authentication required(连接jedis绑定密码或修改redis密码)

Java使用jedis连接redis时出现错误NOAUTH Authentication required

一、问题报错和原因

本地设置了redis的密码,但在远程连接时并没有输入密码,所以无法请求成功!
在这里插入图片描述

二、解决方法一:去除或修改本地redis密码

1、打开redis的安装目录,找到redis.windows.conf配置文件

在这里插入图片描述

2、找到requirepass foobared位置,在下面添加一行requirepass+你想要的修改的密码(该行注意顶格写),删除这行则没有密码

在这里插入图片描述

3、然后重新启动redis再次进入redis-cli命令行窗口则需要输入新的密码

三、解决方法二:连接jedis时绑定密码

1、使用JedisShardInfo时

在这里插入图片描述

2、使用Jedis时

 public void testJedisSingle(){
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        jedis.auth("你的密码");
        jedis.set("aaa","123");
        String aaa = jedis.get("aaa");
        System.out.println(aaa);
        jedis.close();
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

3、使用JedisPool时

  public void pool() {
        JedisPoolConfig config = new JedisPoolConfig();
        //最大连接数
        config.setMaxTotal(30);
        //最大连接空闲数
        config.setMaxIdle(2);

        JedisPool pool = new JedisPool(config, "127.0.0.1", 6379);
        //有密码也可以用下面这个连接方法
        //jedisPool = new JedisPool(Config,"127.0.0.1", 6379 ,3000, redisPassword);
        Jedis jedis = null;
        try  {
            jedis = pool.getResource();
            jedis.auth("你的密码");
            jedis.set("name", "123");
            String name = jedis.get("name");
            System.out.println(name);
        }catch(Exception ex){
            ex.printStackTrace();
        }finally{
            if(jedis != null){
                //关闭连接
                jedis.close();
            }
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/791561
推荐阅读
相关标签
  

闽ICP备14008679号