使用Spring Data Redis保存二进制数据

时间:2017-09-20 13:59:57

标签: java spring-boot spring-data spring-data-redis

我正在使用Spring Data Redis' Redis Repository feature。我想将二进制数据保存到Redis。我创建了一个类似下面的类。

@RedisHash
public class AuthorizationCode
{
    @Id
    private String code;

    private byte[] authentication;
}

这适用于Spring Data。但是,Spring Data Redis将每个字节保存为不同的Redis哈希值。

因此,如果我在对象上执行hgetall,我会看到如下内容:

14397) "authentication.[79]._class"
14398) "java.lang.Byte"
14399) "authentication.[2579]"
14400) "115"
14401) "authentication.[1580]._class"
14402) "java.lang.Byte"
14403) "authentication.[1525]._class"
14404) "java.lang.Byte"
14405) "authentication.[1648]"
14406) "115"
14407) "authentication.[2972]._class"
14408) "java.lang.Byte"
14409) "authentication.[23]"
14410) "115"
14411) "authentication.[507]"
14412) "108"
14413) "authentication.[646]"
14414) "114"
14415) "authentication.[2838]._class"
14416) "java.lang.Byte"
14417) "authentication.[2784]._class"
14418) "java.lang.Byte"

如何使用Spring Data Redis保存这是一个二进制属性?我使用的是Spring Boot 1.5.7。

我可以对数据进行base-64编码。但是,由于Redis支持二进制安全字符串,从Redis角度来看,这似乎并不是必需的。

0 个答案:

没有答案