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

62 lines
1.5 KiB
C++
Raw Normal View History

2014-11-19 00:25:21 +08:00
#pragma once
2015-01-14 23:35:23 +08:00
#include "acl_cpp/acl_cpp_define.hpp"
2014-11-19 00:25:21 +08:00
#include <vector>
#include "acl_cpp/stream/socket_stream.hpp"
2015-01-14 23:35:23 +08:00
#include "acl_cpp/stdlib/string.hpp"
#include "acl_cpp/connpool/connect_client.hpp"
2014-11-19 00:25:21 +08:00
2015-01-14 23:35:23 +08:00
namespace acl
{
class dbuf_pool;
class redis_result;
2015-01-26 19:58:02 +08:00
class redis_request;
2014-11-19 00:25:21 +08:00
2015-01-14 23:35:23 +08:00
class ACL_CPP_API redis_client : public connect_client
2014-11-19 00:25:21 +08:00
{
public:
2015-01-14 23:35:23 +08:00
redis_client(const char* addr, int conn_timeout = 60,
int rw_timeout = 30, bool retry = true);
2014-11-19 00:25:21 +08:00
~redis_client();
2015-01-29 00:38:29 +08:00
bool eof() const;
2014-11-19 00:25:21 +08:00
void close();
2015-01-14 23:35:23 +08:00
socket_stream* get_stream();
2015-01-26 19:58:02 +08:00
void set_slice_request(bool on);
void set_slice_respond(bool on);
2015-01-14 23:35:23 +08:00
const redis_result* run(dbuf_pool* pool, const string& req,
size_t nchildren);
const redis_result* run(dbuf_pool* pool, const redis_request& req,
size_t nchildren);
2015-01-14 23:35:23 +08:00
protected:
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E9BAAF>
virtual bool open();
2014-11-19 00:25:21 +08:00
private:
socket_stream conn_;
char* addr_;
int conn_timeout_;
int rw_timeout_;
bool retry_;
2015-01-14 23:35:23 +08:00
string buf_;
bool slice_req_;
bool slice_res_;
redis_result* get_redis_objects(dbuf_pool* pool, size_t nobjs);
redis_result* get_redis_object(dbuf_pool* pool);
redis_result* get_redis_error(dbuf_pool* pool);
redis_result* get_redis_status(dbuf_pool* pool);
redis_result* get_redis_integer(dbuf_pool* pool);
redis_result* get_redis_string(dbuf_pool* pool);
redis_result* get_redis_array(dbuf_pool* pool);
2015-01-26 19:58:02 +08:00
void put_data(dbuf_pool* pool, redis_result* rr,
const char* data, size_t len);
2014-11-19 00:25:21 +08:00
};
} // end namespace acl