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程序,連接成功。應該也能進行設置密碼和賬戶進行連接,這個我沒有進行測試。

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