Redisson集成进入到项目后,默认使用的是
<code>org.redisson.codec.MarshallingCodec</code>编码器,此编码器跟操作系统的编码有关,会导致不同的服务器存储的内容编码不一致,直接报错,因此需要选择其他的编码器.Redisson默认的编码器如下:
参考官方文档 https://github.com/redisson/redisson/wiki/4.-Data-serialization
Codec class name | Description |
---|---|
| Kryo 5 binary codec(Android compatible) Default codec |
| Kryo 4 binary codec |
| Jackson JSON codec.Stores type information in |
| Jackson JSON codec which doesn't store type id ( |
| Avro binary json codec |
| Protobuf codec |
| Smile binary json codec |
| CBOR binary json codec |
| MsgPack binary json codec |
| Amazon Ion codec |
| JDK Serialization binary codec (Android compatible) |
| LZ4 compression codec.Uses |
| LZ4 Apache Commons compression codec. |
Uses Kryo5Codec
for serialization by default |
| org.redisson.codec.SnappyCodecV2
| Snappy compression codec based on snappy-java project.
Uses Kryo5Codec
for serialization by default |
| org.redisson.codec.MarshallingCodec
| JBoss Marshalling binary codec
Deprecated! |
| org.redisson.client.codec.StringCodec
| String codec |
| org.redisson.client.codec.LongCodec
| Long codec |
| org.redisson.client.codec.ByteArrayCodec
| Byte array codec |
| org.redisson.codec.CompositeCodec
| Allows to mix different codecs as one |
项目中,采用的是redisson-spring-boot-starter集成,也引入了spring-data-redis,参考官方配置https://github.com/redisson/redisson/tree/master/redisson-spring-boot-starter
本项目为了不打破原有的redis配置,并未采用spring.redis.redisson这种配置,而是手动增加了redisson中提供的额外配置接口,实现此接口并注册成为bean后,可以直接设置额外的redisson配置
代码语言:java复制import org.redisson.config.Config;
import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer;
import org.springframework.stereotype.Component;
@Component
public class YourRedissonAutoConfigurationCustomizer implements RedissonAutoConfigurationCustomizer {
@Override
public void customize(Config cfg) {
//cfg.setCodec(new org.redisson.codec.FstCodec());
cfg.setCodec(new org.redisson.codec.SerializationCodec());
}
}
包括NameMapper也可以通过此方法来配置。原理可以查看<code>RedissonAutoConfiguration</code>实现代码