jedis(官网推荐使用)
? ? ? ? 添加maven依赖
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.3.0</version>
</dependency>
这个比较方便,可以直接使用
import redis.clients.jedis.Jedis;
public class RedisTest {
public static void main(String[] args) {
Jedis jedis = new Jedis("127.0.0.1", 6379);
System.out.println(jedis.ping());
jedis.set("name", "csdn");
System.out.println(jedis.get("name"));
jedis.lpush("list", "1");
jedis.lpush("list", "2");
jedis.lpush("list", "rwew");
System.out.println(jedis.lrange("list", 0, -1));
System.out.println(jedis.keys("*"));
}
}
|