skd
skd

Reputation: 165

Unicode returning weird character in StringRedisTemplate java from redis

I am trying to store portugese word 'como você está' for a key in redis. Value is set in redis in unicode format 'como voc\x88 est\xa0184\' in redis. But while fetching the value through StringRedisTemplate in Java am getting weird values like 'como voc� est�184'. I tried the code below, but it is not working.

template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(new StringRedisSerializer());

Here template object is of StringRedisTemplate class. Is there any mechanism to get the special characters back?

Upvotes: 2

Views: 1409

Answers (1)

Renis1235
Renis1235

Reputation: 4690

Try putting this in your application.properties file:

spring.http.encoding.charset=UTF-8 # the encoding of HTTP requests/responses
spring.http.encoding.enabled=true # enable http encoding support
spring.http.encoding.force=true # force the configured encoding

Upvotes: 1

Related Questions