Exemplo n.º 1
0
 /**
  * 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);
     }
   }
 }
Exemplo n.º 2
0
 /**
  * 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);
     }
   }
 }
Exemplo n.º 3
0
 /**
  * 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);
     }
   }
 }
Exemplo n.º 4
0
 /**
  * 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);
     }
   }
 }