【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