08.中文乱码
2024.12.27 需求
prompt> set a 你好
OK
prompt> get a
ä½ å¥½
从navicat上看, 存储的内容是正常的.
2024.12.27 解决
io.vertx.redis.client.impl.ReadableBuffer读取字符串时使用了ISO_8859_1编码.
@Nullable String readLine(int end) {
byte[] bytes = null;
if (end >= this.offset) {
bytes = this.buffer.getBytes(this.offset, end - 1);
this.offset = end + 1;
}
return bytes != null ? new String(bytes, StandardCharsets.ISO_8859_1) : null;
}
- 输出的时候转换一下
// 将ISO-8859-1编码的字符串转换为字节序列
byte[] isoBytes = r.toString().getBytes(StandardCharsets.ISO_8859_1);
// 将这些字节重新解释为UTF-8编码的字符串
String utf8String = new String(isoBytes, StandardCharsets.UTF_8);
logger.info(utf8String);