第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

jedis這么序列化和反序列化

jedis這么序列化和反序列化

fenkapian 2017-05-06 16:32:47
下面就是代碼,麻煩大師解讀一下啊,太難了private Logger logger = LoggerFactory.getLogger(this.getClass());private final JedisPool jedisPool; ?//類似數(shù)據(jù)庫連接池private RuntimeSchema<Seckill> schema = RuntimeSchema.createFrom(Seckill.class);public RedisDao(String ip, int port) { ? ?jedisPool = new JedisPool(ip, port);}public Seckill getSeckill(long seckillId) { ? ?//redis操作邏輯 ? ?try { ? ? ? ?Jedis jedis = jedisPool.getResource(); ? ? ? ?try { ? ? ? ? ? ?String key = "seckill: " + seckillId; ? ? ? ? ? ?byte[] bytes = jedis.get(key.getBytes()); ? ? ? ? ? ?if (bytes != null) { ? ? ? ? ? ? ? ?Seckill seckill = schema.newMessage(); ?//創(chuàng)建空對象 ? ? ? ? ? ? ? ?ProtobufIOUtil.mergeFrom(bytes, seckill, schema); ? ? ? ? ? ? ? ?//seckill被反序列化 ? ? ? ? ? ? ? ?return seckill; ? ? ? ? ? ?} ? ? ? ?} finally { ? ? ? ? ? ?jedis.close(); ? ? ? ?} ? ?} catch (Exception e) { ? ? ? ?logger.error(e.getMessage(), e); ? ?} ? ?return null;}public String putSeckill(Seckill seckill) { ? ?//set Object(Seckill) --> 序列化 --> byte[] ? ?try { ? ? ? ?Jedis jedis = jedisPool.getResource(); ? ? ? ?try { ? ? ? ? ? ?String key = "seckill: " + seckill.getSeckillId(); ? ? ? ? ? ?byte[] bytes = ProtobufIOUtil.toByteArray(seckill, schema, LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE)); ? ? ? ? ? ?//超時(shí)緩存 ? ? ? ? ? ?int timeout = 60 * 60; ?//緩存一小時(shí),單位為秒 ? ? ? ? ? ?String result = jedis.setex(key.getBytes(), timeout, bytes); ? ? ? ? ? ?return result; ? ? ? ?} finally { ? ? ? ? ? ?jedis.close(); ? ? ? ?} ? ?} catch (Exception e) { ? ? ? ?logger.error(e.getMessage(), e); ? ?} ? ?return null;}
查看完整描述

目前暫無任何回答

  • 0 回答
  • 1 關(guān)注
  • 2211 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號