加依赖
<!--redis依赖--> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency>
public class redisDemo { public static void main(String[] args) { // 连接redis Jedis jedis=new Jedis("ip...",6379); jedis.auth("root");//在redis有密码时需要写这步 System.out.println(jedis.ping()); jedis.set("name","aaa"); System.out.println(jedis.get("name")); // 使用完关闭连接 jedis.close(); } }