java 连接 Redis 工具

package cn.com.utils;

import redis.clients.jedis.Jedis;

public class RedisUtils {

    private static final String host = "xxxxx";
    private static final int port = 6379;
    private static final String password = "xxxxx";

    public static Jedis getJedis() {
        Jedis jedis = new Jedis(host, port);
        jedis.auth(password);
        System.out.println(jedis.ping());
        return jedis;
    }
}
<dependencies>
    <dependency>
         <groupId>redis.clients</groupId>
         <artifactId>jedis</artifactId>
         <version>3.3.0</version>
    </dependency>
</dependencies>
public static void main(String[] args) {
     Jedis jedis = RedisUtils.getJedis();
     String hget = jedis.hget("aaaa", "1111");
     System.out.println(hget);
}

 

posted @ 2021-05-17 11:01  Bevis  阅读(109)  评论(0编辑  收藏  举报