Saving binary data using Spring Data Redis

Viewed 878

I'm using Spring Data Redis' Redis Repository feature. I'd like to save binary data to Redis. I created a class the looks like the following.

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

    private byte[] authentication;
}

This does work with Spring Data. However, Spring Data Redis is saving each byte as a distinct Redis hash value.

So if I perform a hgetall on an object, I see something like the following:

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"

How can I have Spring Data Redis save this is a single binary attribute? I'm using Spring Boot 1.5.7.

I could potentially base-64 encode the data. But, as Redis supports binary-safe strings, this doesn't seem necessary from a Redis-only perspective.

0 Answers
Related