acl/lib_acl_cpp/include/acl_cpp/redis/redis_result.hpp

177 lines
4.2 KiB
C++
Raw Normal View History

2015-01-14 23:35:23 +08:00
#pragma once
#include "acl_cpp/acl_cpp_define.hpp"
#include <vector>
namespace acl
{
typedef enum
{
REDIS_RESULT_UNKOWN,
2015-01-14 23:35:23 +08:00
REDIS_RESULT_NIL,
REDIS_RESULT_ERROR,
REDIS_RESULT_STATUS,
REDIS_RESULT_INTEGER,
REDIS_RESULT_STRING,
REDIS_RESULT_ARRAY,
} redis_result_t;
class string;
2015-01-14 23:35:23 +08:00
class dbuf_pool;
class redis_client;
2015-03-29 19:27:41 +08:00
/**
* <EFBFBD><EFBFBD> redis-server <EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> redis-server <EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD>з<EFBFBD><EFBFBD><EFBFBD><EFBFBD>󴴽<EFBFBD>
* redis_result <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* the redis result for redis-server's respond
*/
2015-01-14 23:35:23 +08:00
class ACL_CPP_API redis_result
{
public:
redis_result(dbuf_pool* pool);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> new/delete <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> new <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ʹ<EFBFBD>ڴ<EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD>ڴ<EFBFBD><EFBFBD>ؽ<EFBFBD><EFBFBD>з<EFBFBD><EFBFBD><EFBFBD>
2015-01-14 23:35:23 +08:00
*/
void *operator new(size_t size, dbuf_pool* pool);
void operator delete(void* ptr, dbuf_pool* pool);
/**
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {redis_result_t}
*/
redis_result_t get_type() const
{
return result_type_;
}
/**
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD>
* @return {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵Ķ<EFBFBD>Ӧ<EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
* REDIS_RESULT_ERROR: 1
* REDIS_RESULT_STATUS: 1
* REDIS_RESULT_INTEGER: 1
* REDIS_RESULT_STRING: > 0 ʱ<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD>зֳɷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD>
* REDIS_RESULT_ARRAY: children_->size()
*/
size_t get_size() const;
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ REDIS_RESULT_INTEGER <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>Ӧ<EFBFBD><EFBFBD> 32 λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
* @param success {bool*} <EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL ʱ<EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* @return {int}
*/
int get_integer(bool* success = NULL) const;
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ REDIS_RESULT_INTEGER <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>Ӧ<EFBFBD><EFBFBD> 64 λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
* @param success {bool*} <EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL ʱ<EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* @return {long long int}
*/
long long int get_integer64(bool* success = NULL) const;
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ REDIS_RESULT_STATUS <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD>Ϣ
2015-02-07 22:55:24 +08:00
* @return {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> "" <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-01-14 23:35:23 +08:00
*/
const char* get_status() const;
2015-02-07 22:55:24 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ REDIS_RESULT_ERROR <EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
2015-02-07 22:55:24 +08:00
* @return {const char*} <EFBFBD><EFBFBD><EFBFBD>ؿմ<EFBFBD> "" <EFBFBD><EFBFBD>ʾû<EFBFBD>г<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
*/
const char* get_error() const;
2015-01-14 23:35:23 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>Ӧ<EFBFBD>±<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD> REDIS_RESULT_ARRAY ʱ<EFBFBD><EFBFBD>
* @param i {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>
* @param len {size_t*} <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD> NULL ָ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵij<EFBFBD><EFBFBD><EFBFBD>
2015-02-07 22:55:24 +08:00
* @return {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL <EFBFBD><EFBFBD>ʾ<EFBFBD>±<EFBFBD>Խ<EFBFBD><EFBFBD>
2015-01-14 23:35:23 +08:00
*/
const char* get(size_t i, size_t* len = NULL) const;
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD> REDIS_RESULT_ARRAY ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
* @return {const char**}
*/
const char** gets_argv() const
{
return (const char**) argv_;
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD> REDIS_RESULT_ARRAY ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
* @return {const size_t*}
*/
const size_t* get_lens() const
{
return lens_;
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD>ܳ<EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD> REDIS_RESULT_ARRAY ʱ<EFBFBD><EFBFBD>
* @return {size_t}
*/
size_t get_length() const;
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ REDIS_RESULT_STRING <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-01-27 17:52:50 +08:00
* @param buf {string&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD> buf.clear()
2015-01-29 00:38:29 +08:00
* @return {int} <EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD>ܳ<EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ -1 <EFBFBD><EFBFBD>ʾ<EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>
2015-01-14 23:35:23 +08:00
*/
2015-01-29 00:38:29 +08:00
int argv_to_string(string& buf) const;
int argv_to_string(char* buf, size_t size) const;
2015-01-14 23:35:23 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ REDIS_RESULT_ARRAY <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param size {size_t*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-01-14 23:35:23 +08:00
* @return {const const redis_result*}
*/
const redis_result** get_children(size_t* size) const;
2015-01-14 23:35:23 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ REDIS_RESULT_ARRAY <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>Ӧ<EFBFBD>±<EFBFBD><EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param i {size_t} <EFBFBD>±<EFBFBD>ֵ
* @return {const redis_result*} <EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>ֵԽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>򷵻<EFBFBD> NULL
*/
const redis_result* get_child(size_t i) const;
/**
* <EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>
* @return {dbuf_pool*}
*/
dbuf_pool* get_pool()
{
return pool_;
}
private:
~redis_result();
friend class redis_client;
void reset();
2015-01-14 23:35:23 +08:00
redis_result& set_type(redis_result_t type);
redis_result& set_size(size_t size);
redis_result& put(const char* buf, size_t len);
redis_result& put(const redis_result* rr, size_t idx);
private:
redis_result_t result_type_;
dbuf_pool* pool_;
size_t size_;
size_t idx_;
const char** argv_;
size_t* lens_;
//std::vector<const redis_result*>* children_;
const redis_result** children_;
size_t children_size_;
size_t children_idx_;
};
} // namespace acl