@Test public void testGetSeckill() throws Exception { Seckill seckill = redisDao.getSeckill(id); if (seckill == null) { seckill = seckillDao.queryById(id); if (seckill != null) { String result = redisDao.putSeckill(seckill); System.out.println(result); seckill = redisDao.getSeckill(id); System.out.println(seckill); } } }
public Seckill getSeckill(long seckillId) { try { Jedis jedis = jedisPool.getResource(); try { String key = "seckill:" + seckillId; byte[] bytes = jedis.get(key.getBytes()); if (bytes != null) { Seckill seckill = schema.newMessage(); ProtostuffIOUtil.mergeFrom(bytes, seckill, schema); return seckill; } } finally { jedis.close(); } } catch (Exception e) { logger.error(e.getMessage(), e); } return null; }
RedisDao { public Seckill getSeckill(long seckillId) { try { Jedis jedis = jedisPool.getResource(); try { String key = "seckill:" + seckillId; byte[] bytes = jedis.get(key.getBytes()); if (bytes != null) { Seckill seckill = schema.newMessage(); ProtostuffIOUtil.mergeFrom(bytes, seckill, schema); return seckill; } } finally { jedis.close(); } } catch (Exception e) { logger.error(e.getMessage(), e); } return null; } }
RedisDao { public Seckill getSeckill(long seckillId) { try { Jedis jedis = jedisPool.getResource(); try { String key = "seckill:" + seckillId; byte[] bytes = jedis.get(key.getBytes()); if (bytes != null) { Seckill seckill = schema.newMessage(); ProtostuffIOUtil.mergeFrom(bytes, seckill, schema); return seckill; } } finally { jedis.close(); } } catch (Exception e) { logger.error(e.getMessage(), e); } return null; } RedisDao(String ip, int port); }
RedisDao { public Seckill getSeckill(long seckillId) { try { Jedis jedis = jedisPool.getResource(); try { String key = "seckill:" + seckillId; byte[] bytes = jedis.get(key.getBytes()); if (bytes != null) { Seckill seckill = schema.newMessage(); ProtostuffIOUtil.mergeFrom(bytes, seckill, schema); return seckill; } } finally { jedis.close(); } } catch (Exception e) { logger.error(e.getMessage(), e); } return null; } RedisDao(String ip, int port); Seckill getSeckill(long seckillId); String putSeckill(Seckill seckill); }
RedisDao { public Seckill getSeckill(long seckillId) { try { Jedis jedis = jedisPool.getResource(); try { String key = "seckill:" + seckillId; byte[] bytes = jedis.get(key.getBytes()); if (bytes != null) { Seckill seckill = schema.newMessage(); ProtostuffIOUtil.mergeFrom(bytes, seckill, schema); return seckill; } } finally { jedis.close(); } } catch (Exception e) { logger.error(e.getMessage(), e); } return null; } RedisDao(String ip, int port); Seckill getSeckill(long seckillId); String putSeckill(Seckill seckill);  }