新建一个空maven项目
导入maven
依赖
<dependencies>
<!-- jedis 客户端依赖 -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.6.0</version>
</dependency>
<!-- junit 依赖 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!--slf4j 依赖(不加也不影响运行)-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
</dependencies>
编写测试类JedisTest.java
import org.junit.Test;
import redis.clients.jedis.Jedis;
public class JedisTest {
@Test
public void testSet(){
Jedis jedis = new Jedis("10.50.6.113", 6379);
jedis.auth("root");
jedis.set("name","bar");
String name = jedis.get("name");
System.out.println(name);
jedis.close();
}
}
执行结果: