jedis.set("name","jack"); jedis.set("age","18"); System.out.println("name:"+jedis.get("name")); System.out.println("age:"+jedis.get("age")); System.out.println("pwd:"+jedis.get("pwd")); String rose = JSON.toJSONString(new UserInfo("rose", 2
jedis.set("name","jack");
jedis.set("age","18");
System.out.println("name:"+jedis.get("name"));
System.out.println("age:"+jedis.get("age"));
System.out.println("pwd:"+jedis.get("pwd"));
String rose = JSON.toJSONString(new UserInfo("rose", 28, "66666"));
jedis.set("userInfo",rose);
System.out.println("userInfo:"+jedis.get("userInfo"));
当运行到这里是报了空指针异常
jetdis关闭了
java.lang.NullPointerException
at jetdis .tsetjetdis (ietdis .java:19)
<24 internal calls>
查了许久的原因:是因为取的名是Jedis,导致该变量名未赋值;故而无法使用set和get等redis命令。
修改前:
Jedis jedis= JetdisFortery.getJedisConn();
private Jedis jedis;
修改后:
public class jetdis [
private Jedis jedis;
@Before
public void before(){
jedis= JetdisFortery.getJedisConn();
String pong = jedis .ping ("pong");
System.out.println(pong) ;
}
}
这样就可以了。