Ejemplo n.º 1
0
 /**
  * 获得byte[]型的key
  *
  * @param key
  * @return
  */
 private byte[] getByteKey(K key) {
   if (key instanceof String) {
     String preKey = this.keyPrefix + key;
     return preKey.getBytes();
   } else {
     return SerializeUtils.serialize(key);
   }
 }
Ejemplo n.º 2
0
 @Override
 public V put(K key, V value) throws CacheException {
   logger.debug("根据key从存储 key [" + key + "]");
   try {
     cache.set(getByteKey(key), SerializeUtils.serialize(value));
     return value;
   } catch (Throwable t) {
     throw new CacheException(t);
   }
 }
Ejemplo n.º 3
0
 @Override
 public V get(K key) throws CacheException {
   logger.debug("根据key从Redis中获取对象 key [" + key + "]");
   try {
     if (key == null) {
       return null;
     } else {
       byte[] rawValue = cache.get(getByteKey(key));
       V value = (V) SerializeUtils.deserialize(rawValue);
       return value;
     }
   } catch (Throwable t) {
     throw new CacheException(t);
   }
 }