代码段:
std::function<void(const void *& buf, int& size)> f = [data2, read_buf,key_name](const void *& buf, int& size) {
auto ctx = data2->GetContext();
void *reply = NULL;
auto status = redisGetReply(ctx, &reply);
if (status == REDIS_OK) {
redisReply *r = (redisReply *) reply;
char *data_buf = 0;
int data_size = 0;
if (GetData(r, data_buf, data_size, 3, 2)) {
if (read_buf->capacity() < data_size) {
read_buf->resize(data_size * 2);
}
memcpy(&(*read_buf)[0], data_buf, data_size);
buf = (const void *) &(*read_buf)[0];
size = data_size;
}
}
else {
std::cerr << "[redis-io]: subscribe get message returns status: " << status << ", Error Code : " << ctx->err << ", Error Details : " << ctx->errstr << ", Channel Info : " << key_name << std::endl;
throw runtime_error("[redis-io] subscribe get message returns error.");
}
if (reply != NULL)
freeReplyObject(reply);
};
问题是当redisGetReply(ctx,&amp; reply)返回错误并进入else分支时,打印出的错误消息字符串ctx-&gt; errstr是乱码,这是不可读的,如下所示:
如何解决问题以正常显示错误消息?非常感谢。