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

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();
    }

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);
        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. redis修改密码

    2024-01-24 14:04:02       28 阅读
  2. Redis 设置密码

    2024-01-24 14:04:02       61 阅读
  3. redis开启密码验证

    2024-01-24 14:04:02       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-24 14:04:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-24 14:04:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-24 14:04:02       82 阅读
  4. Python语言-面向对象

    2024-01-24 14:04:02       91 阅读

热门阅读

  1. 蒙特卡洛方法概述

    2024-01-24 14:04:02       54 阅读
  2. Golang中int, int8, int16, int32, int64和uint区别

    2024-01-24 14:04:02       51 阅读
  3. 02_正则表达式的应用

    2024-01-24 14:04:02       49 阅读
  4. Flowable使用docker中MySQL8,Springboot启动出错

    2024-01-24 14:04:02       56 阅读
  5. el-select选项过多导致页面卡顿,路由跳转卡顿

    2024-01-24 14:04:02       49 阅读
  6. 机器的世界模型与人类的世界模型

    2024-01-24 14:04:02       50 阅读
  7. 【Spring Boot 3】【JPA】枚举类型持久化

    2024-01-24 14:04:02       50 阅读
  8. ES6笔记-symbol

    2024-01-24 14:04:02       50 阅读
  9. 最小生成树 prim + kruskal

    2024-01-24 14:04:02       44 阅读
  10. NLP自然语言处理介绍

    2024-01-24 14:04:02       50 阅读
  11. 2024.1.20 Python学习笔记7:字符串常见处理函数

    2024-01-24 14:04:02       51 阅读
  12. C++中模板的使用

    2024-01-24 14:04:02       56 阅读
  13. Python之list

    2024-01-24 14:04:02       42 阅读