2023-07-19 19:07:53 +08:00
|
|
|
|
//
|
|
|
|
|
// Created by shuxin <20><><EFBFBD><EFBFBD>zheng on 2023/7/19.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-07-20 19:24:18 +08:00
|
|
|
|
#include "redis_type.h"
|
|
|
|
|
|
2023-07-19 19:07:53 +08:00
|
|
|
|
namespace pkv {
|
|
|
|
|
|
2023-07-24 11:10:14 +08:00
|
|
|
|
class redis_object;
|
|
|
|
|
using shared_redis = std::shared_ptr<redis_object>;
|
2023-07-19 19:07:53 +08:00
|
|
|
|
|
|
|
|
|
class redis_object {
|
|
|
|
|
public:
|
2023-07-24 11:10:14 +08:00
|
|
|
|
explicit redis_object(redis_object* parent);
|
|
|
|
|
~redis_object() = default;
|
2023-07-21 14:20:47 +08:00
|
|
|
|
|
|
|
|
|
redis_object(const redis_object&) = delete;
|
|
|
|
|
void operator=(const redis_object&) = delete;
|
|
|
|
|
|
|
|
|
|
public:
|
2023-07-20 19:24:18 +08:00
|
|
|
|
const char* update(const char* data, size_t& len);
|
2023-07-19 19:07:53 +08:00
|
|
|
|
|
2023-07-20 22:56:34 +08:00
|
|
|
|
[[nodiscard]] bool finish() const {
|
2023-07-20 19:24:18 +08:00
|
|
|
|
return status_ == redis_s_finish;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-20 22:56:34 +08:00
|
|
|
|
[[nodiscard]] bool failed() const {
|
2023-07-20 19:24:18 +08:00
|
|
|
|
return status_ == redis_s_null;
|
2023-07-19 19:07:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-20 22:56:34 +08:00
|
|
|
|
[[nodiscard]] int get_status() const {
|
2023-07-19 19:07:53 +08:00
|
|
|
|
return status_;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-20 22:56:34 +08:00
|
|
|
|
[[nodiscard]] acl::redis_result_t get_type() const {
|
2023-07-21 14:20:47 +08:00
|
|
|
|
return me_ ? me_->get_type() : acl::REDIS_RESULT_UNKOWN;
|
2023-07-20 19:24:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-21 19:12:12 +08:00
|
|
|
|
[[nodiscard]] const char* get_cmd() const;
|
|
|
|
|
|
2023-07-23 23:18:37 +08:00
|
|
|
|
[[nodiscard]] const char* get_str() const;
|
|
|
|
|
|
2023-07-24 11:10:14 +08:00
|
|
|
|
[[nodiscard]] const std::vector<shared_redis>& get_objects() const {
|
2023-07-23 23:18:37 +08:00
|
|
|
|
return objs_;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-20 19:24:18 +08:00
|
|
|
|
public:
|
2023-07-21 16:20:04 +08:00
|
|
|
|
redis_object& set_status(const std::string& data, bool return_parent = false);
|
|
|
|
|
redis_object& set_error(const std::string& data, bool return_parent = false);
|
|
|
|
|
redis_object& set_number(int n, bool return_parent = false);
|
|
|
|
|
redis_object& set_string(const std::string& data, bool return_parent = false);
|
|
|
|
|
redis_object& create_child();
|
|
|
|
|
|
2023-07-20 19:24:18 +08:00
|
|
|
|
bool to_string(acl::string& out) const;
|
|
|
|
|
|
2023-07-19 19:07:53 +08:00
|
|
|
|
private:
|
|
|
|
|
acl::dbuf_pool* dbuf_;
|
2023-07-21 16:20:04 +08:00
|
|
|
|
redis_object* parent_;
|
2023-07-21 14:20:47 +08:00
|
|
|
|
int status_ = redis_s_begin;
|
|
|
|
|
acl::redis_result* me_ = nullptr;
|
2023-07-24 11:10:14 +08:00
|
|
|
|
std::vector<shared_redis> objs_;
|
2023-07-19 19:07:53 +08:00
|
|
|
|
|
|
|
|
|
std::string buf_;
|
2023-07-21 14:20:47 +08:00
|
|
|
|
int cnt_ = 0;
|
2023-07-24 11:10:14 +08:00
|
|
|
|
shared_redis obj_ = nullptr;
|
2023-07-19 19:07:53 +08:00
|
|
|
|
|
|
|
|
|
private:
|
2023-07-20 19:24:18 +08:00
|
|
|
|
static void put_data(acl::dbuf_pool*, acl::redis_result*, const char*, size_t);
|
|
|
|
|
const char* get_line(const char*, size_t&, bool&);
|
2023-07-21 14:20:47 +08:00
|
|
|
|
const char* get_length(const char*, size_t&, int&, bool&);
|
2023-07-20 19:24:18 +08:00
|
|
|
|
const char* get_data(const char*, size_t&, size_t);
|
|
|
|
|
|
|
|
|
|
const char* parse_object(const char*, size_t&);
|
2023-07-19 19:07:53 +08:00
|
|
|
|
|
|
|
|
|
public:
|
2023-07-20 19:24:18 +08:00
|
|
|
|
const char* parse_begin(const char* data, size_t& len);
|
|
|
|
|
const char* parse_status(const char* data, size_t& len);
|
|
|
|
|
const char* parse_error(const char* data, size_t& len);
|
|
|
|
|
const char* parse_number(const char* data, size_t& len);
|
|
|
|
|
const char* parse_strlen(const char* data, size_t& len);
|
|
|
|
|
const char* parse_string(const char* data, size_t& len);
|
|
|
|
|
const char* parse_strend(const char* data, size_t& len);
|
|
|
|
|
const char* parse_arlen(const char* data, size_t& len);
|
|
|
|
|
const char* parse_array(const char* data, size_t& len);
|
2023-07-19 19:07:53 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace pkv
|