/** * 从distcache中取数据 * * @parameter mckey 取出数据的key */ public byte[] getByDistCache(String bizName, int userId) { byte[] data = new byte[0]; synchronized (lock) { if (bizMap.containsKey(bizName)) { BizType bizType = bizMap.get(bizName); long key = bizType.getType(); key = (key << 32) + userId; DistCacheAdapter adapter = bizType.getDistcacheAdapter(); try { data = adapter.get(key); } catch (Exception e) { e.printStackTrace(); } } else { Init(); // 失败后再次初始化 } } return data; }
/** * 向distcache中插入数据 * * @param type * @param userId * @param data * @return */ public boolean setByDistCache(String type, int userId, byte[] data) { boolean result = true; synchronized (lock) { if (bizMap.containsKey(type)) { BizType bizType = bizMap.get(type); long key = bizType.getType(); key = (key << 32) + userId; DistCacheAdapter adapter = bizType.getDistcacheAdapter(); try { adapter.set(key, data); } catch (Exception e) { e.printStackTrace(); result = false; } } else { Init(); // 失败后再次初始化 } } return result; }