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); }