Merge branch 'gitee-master' into gitlab-upstream

This commit is contained in:
zhengshuxin 2023-07-26 18:01:49 +08:00
commit fe9a975f29
5 changed files with 25 additions and 26 deletions

View File

@ -27,7 +27,7 @@ bool redis_handler::handle() {
#if 0 #if 0
{ {
acl::string tmp; std::string tmp;
for (size_t i = 0; i < objs.size(); i++) { for (size_t i = 0; i < objs.size(); i++) {
tmp += "+OK\r\n"; tmp += "+OK\r\n";
} }
@ -43,7 +43,7 @@ bool redis_handler::handle() {
} }
} }
acl::string buf; std::string buf;
if (!builder_.to_string(buf)) { if (!builder_.to_string(buf)) {
builder_.clear(); builder_.clear();
return false; return false;
@ -54,7 +54,7 @@ bool redis_handler::handle() {
//if (objs.size() >= 20) { printf("reply len=%zd\r\n", buf.size()); } //if (objs.size() >= 20) { printf("reply len=%zd\r\n", buf.size()); }
//printf(">>>buf=[%s]\r\n", buf.c_str()); //printf(">>>buf=[%s]\r\n", buf.c_str());
return conn_.write(buf) != -1; return conn_.write(buf.c_str(), buf.size()) != -1;
} }
bool redis_handler::handle_one(const redis_object &obj) { bool redis_handler::handle_one(const redis_object &obj) {
@ -89,8 +89,8 @@ bool redis_handler::handle_one(const redis_object &obj) {
return hgetall(obj); return hgetall(obj);
} }
acl::string err; std::string err;
err.format("%s not support yet", cmd); err.append(cmd).append("not support yet");
logger_error("cmd=%s not support!", cmd); logger_error("cmd=%s not support!", cmd);
builder_.create_object().set_error(err); builder_.create_object().set_error(err);
return true; return true;
@ -115,8 +115,8 @@ bool redis_handler::set(const redis_object &obj) {
return false; return false;
} }
#if 1 #if 0
acl::string buff; std::string buff;
coder_.create_object().set_string(value); coder_.create_object().set_string(value);
coder_.to_string(buff); coder_.to_string(buff);
coder_.clear(); coder_.clear();
@ -238,7 +238,7 @@ bool redis_handler::hset(const redis_object &obj) {
.create_child().set_string(name, true) .create_child().set_string(name, true)
.create_child().set_string(value, true); .create_child().set_string(value, true);
acl::string buff; std::string buff;
if (!builder.to_string(buff)) { if (!builder.to_string(buff)) {
logger_error("build data error"); logger_error("build data error");
return false; return false;

View File

@ -71,7 +71,7 @@ redis_object& redis_coder::create_object() {
return *obj; return *obj;
} }
bool redis_coder::to_string(acl::string& out) const { bool redis_coder::to_string(std::string& out) const {
for (const auto& obj : objs_) { for (const auto& obj : objs_) {
if (!obj->to_string(out)) { if (!obj->to_string(out)) {
return false; return false;
@ -118,14 +118,14 @@ bool test_redis_parse_once(const char* filepath) {
printf(">>>%s: parse success<<<\r\n", __func__); printf(">>>%s: parse success<<<\r\n", __func__);
acl::string out; std::string out;
if (!parser.to_string(out)) { if (!parser.to_string(out)) {
printf(">>>%s: build failed<<<\r\n", __func__); printf(">>>%s: build failed<<<\r\n", __func__);
return false; return false;
} }
if (out != buf) { if (out != std::string(buf.c_str())) {
printf(">>>%s: build failed<<<\r\n", __func__); printf(">>>%s: build failed<<<\r\n", __func__);
printf("output:\r\n|%s|\r\n", out.c_str()); printf("output:\r\n|%s|\r\n", out.c_str());
printf("input:\r\n|%s|\r\n", buf.c_str()); printf("input:\r\n|%s|\r\n", buf.c_str());
@ -134,7 +134,7 @@ bool test_redis_parse_once(const char* filepath) {
filetmp += ".tmp"; filetmp += ".tmp";
acl::ofstream fp; acl::ofstream fp;
if (fp.open_trunc(filetmp)) { if (fp.open_trunc(filetmp)) {
fp.write(out); fp.write(out.c_str(), out.size());
} }
return false; return false;
@ -168,14 +168,14 @@ bool test_redis_parse_stream(const char* filepath) {
} }
printf(">>%s(%d): parse successfully<<<\r\n", __func__, __LINE__); printf(">>%s(%d): parse successfully<<<\r\n", __func__, __LINE__);
acl::string out; std::string out;
if (!parser.to_string(out)) { if (!parser.to_string(out)) {
printf(">>%s(%d): build failed<<\r\n", __func__, __LINE__); printf(">>%s(%d): build failed<<\r\n", __func__, __LINE__);
return false; return false;
} }
if (out != buf) { if (out != std::string(buf.c_str())) {
printf("%s\r\n", out.c_str()); printf("%s\r\n", out.c_str());
printf(">>%s(%d): build failed<<\r\n", __func__, __LINE__); printf(">>%s(%d): build failed<<\r\n", __func__, __LINE__);
return false; return false;
@ -215,7 +215,7 @@ bool test_redis_build() {
.create_child().set_string("value3", true); .create_child().set_string("value3", true);
#endif #endif
acl::string buf; std::string buf;
if (builder.to_string(buf)) { if (builder.to_string(buf)) {
const char* cmd = obj.get_cmd(); const char* cmd = obj.get_cmd();
printf("%s(%d): build redis successfully, cmd=%s\r\n", printf("%s(%d): build redis successfully, cmd=%s\r\n",

View File

@ -29,7 +29,7 @@ public:
public: public:
[[nodiscard]] redis_object& create_object(); [[nodiscard]] redis_object& create_object();
bool to_string(acl::string& out) const; bool to_string(std::string& out) const;
private: private:
std::vector<redis_object*> objs_; std::vector<redis_object*> objs_;

View File

@ -377,7 +377,7 @@ const char* redis_object::get_line(const char* data, size_t& len,
return data; return data;
} }
bool redis_object::to_string(acl::string& out) const { bool redis_object::to_string(std::string& out) const {
#define USE_UNIX_CRLF #define USE_UNIX_CRLF
#ifdef USE_UNIX_CRLF #ifdef USE_UNIX_CRLF
#define CRLF "\n" #define CRLF "\n"
@ -386,7 +386,7 @@ bool redis_object::to_string(acl::string& out) const {
#endif #endif
if (!objs_.empty()) { if (!objs_.empty()) {
out.format_append("*%zd%s", objs_.size(), CRLF); out.append("*").append(std::to_string(objs_.size())).append(CRLF);
for (const auto& obj : objs_) { for (const auto& obj : objs_) {
if (!obj->to_string(out)) { if (!obj->to_string(out)) {
@ -399,16 +399,17 @@ bool redis_object::to_string(acl::string& out) const {
switch (type_) { switch (type_) {
case REDIS_OBJ_STATUS: case REDIS_OBJ_STATUS:
out.format_append("+%s%s", buf_.c_str(), CRLF); out.append("+").append(buf_.c_str(), buf_.size()).append(CRLF);
break; break;
case REDIS_OBJ_ERROR: case REDIS_OBJ_ERROR:
out.format_append("-%s%s", buf_.c_str(), CRLF); out.append("-").append(buf_.c_str(), buf_.size()).append(CRLF);
break; break;
case REDIS_OBJ_INTEGER: case REDIS_OBJ_INTEGER:
out.format_append(":%s%s", buf_.c_str(), CRLF); out.append(":").append(buf_.c_str(), buf_.size()).append(CRLF);
break; break;
case REDIS_OBJ_STRING: case REDIS_OBJ_STRING:
out.format_append("$%zd%s%s%s", buf_.size(), CRLF, buf_.c_str(), CRLF); out.append("$").append(std::to_string(buf_.size())).append(CRLF)
.append(buf_.c_str(), buf_.size()).append(CRLF);
break; break;
//case acl::REDIS_RESULT_ARRAY: //case acl::REDIS_RESULT_ARRAY:
// break; // break;
@ -435,9 +436,7 @@ redis_object& redis_object::set_error(const std::string& data,
redis_object& redis_object::set_number(int n, bool return_parent) { redis_object& redis_object::set_number(int n, bool return_parent) {
type_ = REDIS_OBJ_INTEGER; type_ = REDIS_OBJ_INTEGER;
buf_ = std::to_string(n);
std::string buf = std::to_string(n);
buf_ = buf;
return return_parent ? *parent_ : *this; return return_parent ? *parent_ : *this;
} }

View File

@ -68,7 +68,7 @@ public:
redis_object& set_string(const std::string& data, bool return_parent = false); redis_object& set_string(const std::string& data, bool return_parent = false);
redis_object& create_child(); redis_object& create_child();
bool to_string(acl::string& out) const; bool to_string(std::string& out) const;
private: private:
int status_ = redis_s_begin; int status_ = redis_s_begin;