- String tbname = "login";
-
- //获取mysql表主键值--redis启动时
- long id = MySQL.getID(tbname);
- //设置redis主键值--redis启动时
- redisService.set(tbname, String.valueOf(id));
- System.out.println(id);
- long l = redisService.incr(tbname);
- System.out.println(l);
- Login login = new Login();
- login.setId(l);
- login.setName("redis");
- redisService.hmset(String.valueOf(login.getId()), login);
- boolean b = MySQL.insert("insert into login(id,name) values(" + login.getId() + ",'" + login.getName() + "')");
- /**
- *
- * 队列处理器更新mysql失败:
- *
- * 清除缓存数据,同时主键值自减
- */
- if (!b){
- redisService.delKeyAndDecr(tbname, "Login:"+String.valueOf(login.getId()));
- }
- System.out.println(redisService.exists("Login:"+String.valueOf(login.getId())));
- System.out.println(redisService.get(tbname));