/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param nodeName * @param key * @param t * @throws CacheException <br> */ @Override public <T> void putValue(String nodeName, String key, T t) throws CacheException { if (t != null) { try { cluster.hset(nodeName, key, SerializationUtil.serial(t)); } catch (UtilException e) { throw new CacheException(e); } catch (Exception e) { throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e); } } }
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param clazz * @param nodeName * @param key * @return * @throws CacheException <br> */ @Override public <T> T getValue(Class<T> clazz, String nodeName, String key) throws CacheException { T value = null; try { value = SerializationUtil.unserial(clazz, cluster.hgetBytes(nodeName, key)); } catch (UtilException e) { throw new CacheException(e); } catch (Exception e) { throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e); } return value; }
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param nodeName * @param key * @param t * @throws CacheException <br> */ @Override public <T> void putValue(String nodeName, String key, T t) throws CacheException { if (t != null) { ShardedJedis shardedJedis = null; try { shardedJedis = shardedPool.getResource(); shardedJedis.hset(nodeName.getBytes(), key.getBytes(), SerializationUtil.serial(t)); } catch (UtilException e) { throw new CacheException(e); } catch (Exception e) { throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e); } finally { shardedPool.returnResourceObject(shardedJedis); } } }
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param clazz * @param nodeName * @param key * @return * @throws CacheException <br> */ @Override public <T> T getValue(Class<T> clazz, String nodeName, String key) throws CacheException { T value = null; ShardedJedis shardedJedis = null; try { shardedJedis = shardedPool.getResource(); value = SerializationUtil.unserial(clazz, shardedJedis.hget(nodeName.getBytes(), key.getBytes())); } catch (UtilException e) { throw new CacheException(e); } catch (Exception e) { throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e); } finally { shardedPool.returnResourceObject(shardedJedis); } return value; }
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param clazz * @param nodeName * @return * @throws CacheException <br> */ @Override public <T> Map<String, T> getNode(Class<T> clazz, String nodeName) throws CacheException { Map<String, T> map = null; try { Map<byte[], byte[]> hmap = cluster.hgetAllBytes(nodeName); if (CommonUtil.isNotEmpty(hmap)) { map = new HashMap<String, T>(); for (Entry<byte[], byte[]> entry : hmap.entrySet()) { map.put(new String(entry.getKey()), SerializationUtil.unserial(clazz, entry.getValue())); } } } catch (UtilException e) { throw new CacheException(e); } catch (Exception e) { throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e); } return map; }
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param nodeName * @param node * @throws CacheException <br> */ @Override public <T> void putNode(String nodeName, Map<String, T> node) throws CacheException { if (CommonUtil.isNotEmpty(node)) { Map<byte[], byte[]> hmap = new HashMap<byte[], byte[]>(); try { for (Entry<String, T> entry : node.entrySet()) { byte[] value = SerializationUtil.serial(entry.getValue()); if (value != null) { hmap.put(entry.getKey().getBytes(), value); } } cluster.hmsetBytes(nodeName, hmap); } catch (UtilException e) { throw new CacheException(e); } catch (Exception e) { throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e); } } }
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param clazz * @param nodeName * @return * @throws CacheException <br> */ @Override public <T> Map<String, T> getNode(Class<T> clazz, String nodeName) throws CacheException { ShardedJedis shardedJedis = null; Map<String, T> map = null; try { shardedJedis = shardedPool.getResource(); Map<byte[], byte[]> hmap = shardedJedis.hgetAll(nodeName.getBytes()); if (CommonUtil.isNotEmpty(hmap)) { map = new HashMap<String, T>(); for (Entry<byte[], byte[]> entry : hmap.entrySet()) { map.put(new String(entry.getKey()), SerializationUtil.unserial(clazz, entry.getValue())); } } } catch (UtilException e) { throw new CacheException(e); } catch (Exception e) { throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e); } finally { shardedPool.returnResourceObject(shardedJedis); } return map; }
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param nodeName * @param node * @throws CacheException <br> */ @Override public <T> void putNode(String nodeName, Map<String, T> node) throws CacheException { if (CommonUtil.isNotEmpty(node)) { ShardedJedis shardedJedis = null; Map<byte[], byte[]> hmap = new HashMap<byte[], byte[]>(); try { shardedJedis = shardedPool.getResource(); for (Entry<String, T> entry : node.entrySet()) { byte[] value = SerializationUtil.serial(entry.getValue()); if (value != null) { hmap.put(entry.getKey().getBytes(), value); } } shardedJedis.hmset(nodeName.getBytes(), hmap); } catch (UtilException e) { throw new CacheException(e); } catch (Exception e) { throw new CacheException(ErrorCodeDef.CACHE_ERROR_10002, "serial map failed!", e); } finally { shardedPool.returnResourceObject(shardedJedis); } } }