redissonClient.getBucket("key01", Commonlang3RedissonSerializer.INSTANCE).get()
自定义序列化方式
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.Unpooled;
import org.apache.commons.lang3.SerializationUtils;
import org.redisson.client.codec.BaseCodec;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;
public class Commonlang3RedissonSerializer extends BaseCodec {
public static final Commonlang3RedissonSerializer INSTANCE = new Commonlang3RedissonSerializer();
private final Encoder encoder = o -> {
byte[] serialize = SerializationUtils.serialize((Serializable) o);
return Unpooled.wrappedBuffer(serialize);
};
private final Decoder<Object> decoder = new Decoder<Object>() {
public Object decode(ByteBuf buf, State state) {
ByteBufInputStream byteBufInputStream = new ByteBufInputStream(buf);
return SerializationUtils.deserialize(byteBufInputStream);
}
};
@Override
public Decoder<Object> getValueDecoder() {
return decoder;
}
@Override
public Encoder getValueEncoder() {
return encoder;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)