用string作为key,用byte[]作为value请问改如何用RedisTemplate来实现?本来是想,写一个spring redis的解析类,可将protobuf message与其对应的byte[]转换
但我发现貌似不可以,protobuf message的抽象父类GeneratedMessage以及实现的接口MessageOrBuilder中都不含有parseFrom的函数不知哪位高手有啥办法。或者,实在不行,我该怎么写这个解析类或者啥办法能实现我用string作为key,用byte[]作为value来操作读取、写入由protobuf序列化为的byte[]

解决方案 »

  1.   

    哎,单独写一个存byte[]的解析器倒是可以解决这个问题。但请各位高手指点,有没有啥办法能实现我想要的,上面那种直接protubuf类到byte[]直接在解析器中转换好?public class ByteRedisSerializer implements RedisSerializer<byte[]> {
    private final Charset charset; public ByteRedisSerializer() {
    this(Charset.forName("UTF8"));
    } public ByteRedisSerializer(Charset charset) {
    Assert.notNull(charset, "Charset must not be null!");
    this.charset = charset;
    } @Override
    public byte[] serialize(byte[] t) throws SerializationException {
    return t;
    } @Override
    public byte[] deserialize(byte[] bytes) throws SerializationException {
    return bytes;
    }}