1、环境准备
1.1、引入依赖
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
1.2、创建jedis对象
public class TestJedis {
public static void main(String[] args) {
Jedis jedis = new Jedis("192.168.56.105",7000);
jedis.select(0);
Set<String> keys = jedis.keys("*");
keys.forEach(key-> System.out.println("key="+key));
jedis.close();
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3310903809bd9d412e942c5ae52e1fde.png)
1.3、常用的操作命令
@Test
public void testKeys(){
jedis. del(" name");
Boolean name = jedis . exists("name");
System . out . print1n(name);
Long age1 = jedis. ttl("newage");
System . out . println(age1);
String s = jedis . randomKey();
String name1 = jedis. type("name");
System . out . println(name1);
String maps = jedis. type(" maps" );
System. out. println(maps);
}