Java creating Redis key and content with strange characters
Asked Answered
S

3

14

I'm creating a new Redis key (and content) with the following code:

private static final String KEY_ESTADOS = "estados";
private HashOperations<String, String, Object> hashOperations;

public void add(final Estado estado) {
    hashOperations.put(KEY_ESTADOS, estado.getSigla(), estado);
}

Instead of create a key "estados" on Redis, it's creating a key name ""\xac\xed\x00\x05t\x00\aestados"

enter image description here

The key content is also with strange characters: enter image description here

Anybody knows how to fix this?

The Estados class implements Serializable but I would like save it's content in pure json so I could change HashOperations to instead of . What do you recommend to serialize to json and deserialize it back to object?

Thanks

Sardius answered 20/10, 2018 at 14:52 Comment(0)
F
-3

Add GenericJackson2JsonRedisSerializer to convert to json and set valueSerializer. This blog post may help you

Fontanez answered 20/10, 2018 at 16:41 Comment(1)
That "blog post" is a dangerous link.Saloop
S
13

To solve the problem about the redis key, hash key and content value I had to add the following lines on RedisTemplate method:

template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
Sardius answered 20/10, 2018 at 18:43 Comment(0)
G
0

I had the same issue while using Socket and I fixed it due replacing ObjectOutputStream with OutputStream. Maybe that helps.

Godart answered 24/10, 2022 at 16:5 Comment(0)
F
-3

Add GenericJackson2JsonRedisSerializer to convert to json and set valueSerializer. This blog post may help you

Fontanez answered 20/10, 2018 at 16:41 Comment(1)
That "blog post" is a dangerous link.Saloop

© 2022 - 2024 — McMap. All rights reserved.