1. String类型
public static void main(String[] args){
Jedis jedis = new Jedis("localhost",6379);
//指定数据库 默认是0
jedis.select(2);
//使用ping命令,测试连接是否成功
String result = jedis.ping();
System.out.println(result);
//添加一条数据
jedis.set("user:name","limengjuan");
jedis.set("user:age","20");
//添加多条数据 参数奇数为key,参数偶数为value
jedis.mset("user:address","湖南郴州","user:sex","女");
//获取一条数据
String username = jedis.get("user:name");
System.out.println("username:"+username);
//获取多条数据
List<String> mget = jedis.mget("user:age", "user:address", "user:sex");
for (String dto:mget) {
System.out.println(dto);
}
//删除
//jedis.del("user:name");
}
控制台打印结果如下:
redis中存储结果为: