【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

posted @ 2022-03-04 11:01  逆火狂飙  阅读(868)  评论(1)    收藏  举报
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东