【java/redis】java程序如何使用jedis訪問有密碼限制的redis


【依賴】

        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.3.2</version>
        </dependency>

【代碼】

import redis.clients.jedis.Jedis;

....  

      //連接本地的 Redis 服務
        Jedis jedis = new Jedis("192.168.32.128");
        jedis.auth("123456");

        System.out.println("連接成功");
        //設置 redis 字符串數據
        jedis.set("wto", "www.wto.com");
        // 獲取存儲的數據並輸出
        System.out.println("redis 存儲的字符串為: "+ jedis.get("wto"));

以上紅色粗體為關鍵

【輸出】

連接成功
redis 存儲的字符串為: www.wto.com

參考資料:

https://www.runoob.com/redis/redis-java.html

 

END


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM