|
@@ -3,6 +3,7 @@ package com.diagbot.config;
|
|
|
import com.esotericsoftware.kryo.Kryo;
|
|
|
import com.esotericsoftware.kryo.io.Input;
|
|
|
import com.esotericsoftware.kryo.io.Output;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
|
|
import org.springframework.data.redis.serializer.SerializationException;
|
|
|
import org.xerial.snappy.Snappy;
|
|
@@ -14,6 +15,7 @@ import java.io.ByteArrayOutputStream;
|
|
|
* @author: gaodm
|
|
|
* @time: 2021/12/16 13:12
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
public class KryoRedisSerializer<T> implements RedisSerializer<T> {
|
|
|
public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
|
|
|
|
|
@@ -43,8 +45,9 @@ public class KryoRedisSerializer<T> implements RedisSerializer<T> {
|
|
|
output.flush();
|
|
|
return Snappy.compress(baos.toByteArray()); //压缩
|
|
|
} catch (Exception e) {
|
|
|
- throw new SerializationException("Could not write Data: " + e.getMessage(), e);
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
|
+ return EMPTY_BYTE_ARRAY;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -61,8 +64,9 @@ public class KryoRedisSerializer<T> implements RedisSerializer<T> {
|
|
|
try (Input input = new Input(Snappy.uncompress(bytes))) { //解压
|
|
|
return (T) kryo.readClassAndObject(input);
|
|
|
} catch (Exception e) {
|
|
|
- throw new SerializationException("Could not read Data: " + e.getMessage(), e);
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
}
|