public void init() { topic = redisson.getTopic(Contants.TOPIC_PREFIX_KEY + name); topic.addListener( new MessageListener<OperateObject>() { public void onMessage(String channel, OperateObject message) { Object key = message.getKey(); Cache cache = getEhCache(); if (null != cache) { if (message.getOperateType().equals(OperateType.PUT)) { cache.remove(key); } else if (message.getOperateType().equals(OperateType.DELETE)) { cache.remove(key); } else if (message.getOperateType().equals(OperateType.CLEAR)) { cache.removeAll(); } else { logger.error("ERROR OPERATE TYPE !!!"); } } } }); }
private void publish(Object key, OperateType operateType) { OperateObject object = new OperateObject(); object.setKey(key); object.setOperateType(operateType); try { topic.publish(object); } catch (Exception e) { logger.error(e.getMessage()); } }