Thursday, September 12, 2019

Redis + Java + Redisson = Encoding issues

Using Reddison/Java to save to Redis, I noticed when using the redis-cli command-line client, that the saved records were encoded funny, as follows:


127.0.0.1:6379> hgetall SessionMap
 1) "\xfc(gB2muKkpNJVgDhiXQA5fGELNcFkFcBszLh5wqcXX"
 2) "\xfc\x0214"
 3) "\xfc(lh9wm3gpV767f6KrvZfVnHO5gKKUFMHfL1KJEsRC"
 4) "\xfc\x0214"

Following from their online documentation, in Java code, I had the following:

RMap map = redisson.getMap("SessionMap");
Turns out we need to specify the encoding of the string by using this bit of code instead:

RMap map = redisson.getMap("SessionMap", new StringCodec("UTF-8"));