【问题标题】:Unicode returning weird character in StringRedisTemplate java from redisUnicode从redis返回StringRedisTemplate java中的奇怪字符
【发布时间】:2021-07-15 06:49:10
【问题描述】:

我正在尝试将葡萄牙语单词 'como você está' 存储为 redis 中的键。值在 redis 中以 unicode 格式 'como voc\x88 est\xa0184\' 在 redis 中设置。但是,在 Java 中通过StringRedisTemplate 获取值时,我得到了像'como voc� est�184' 这样的奇怪值。我尝试了下面的代码,但它不起作用。

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

这里的模板对象属于StringRedisTemplate 类。有什么机制可以找回特殊字符吗?

【问题讨论】:

  • 不确定您的声明是否正确。您所显示的值应打印在不支持 UTF-8 的控制台/文件上。

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


【解决方案1】:

尝试将其放入您的 application.properties 文件中:

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

【讨论】:

  • 直接从redis获取数据时出现数据错误,无法正常工作。它不是弹簧靴的东西。我试过了,它不起作用
猜你喜欢
  • 2014-04-09
  • 2019-11-14
  • 1970-01-01
  • 1970-01-01
  • 2019-07-05
  • 2017-07-04
  • 2018-03-11
  • 2019-07-27
  • 2014-02-28
相关资源
最近更新 更多