java连接ubuntu中的redis出错

一、前面介绍了在ubuntu中安装redis
二、今天写java程序来连接redis却出现了错误
三、错误如下
这里写图片描述

四、程序代码如下

String host = "123.57.36.98";
    int port = 6379;
    //Jedis jedis = new Jedis(host, port);
    /**
     * 单机单链接方式
     * 使用java代码操作redis
     * 一般只用于测试代码
     * @throws Exception
     */
    @Test
    public void test1() throws Exception {
        Jedis jedis = new Jedis(host, port);
        jedis.set("crxy", "www.crxy.cn");
        String string = jedis.get("crxy");
        System.out.println(string);
    }

五、确认程序代码没有问题,仔细查看错误发现如下的信息

DENIED Redis is running in protected mode 
because protected mode is enabled, no bind address was specified, no authentication password 
is requested to clients

他说名redis是受保护的,不能进行没有绑定地址和密码的进行连接,
五、解决办法,修改redis.conf配置文件找到如下地方,把原来的yes改为no
这里写图片描述
六、重新启动redis,再次运行java程序,连接成功。应该也能进行设置密码和账户进行连接,这个我没有进行测试。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章