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-03-29 19:27:41 +08:00
|
|
|
|
/**
|
|
|
|
|
* redis <EFBFBD>ͻ<EFBFBD><EFBFBD>˶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD>࣬ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ཫ<EFBFBD><EFBFBD>֯<EFBFBD>õ<EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>
|
|
|
|
|
* ͬʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳<EFBFBD><EFBFBD><EFBFBD> connect_client <EFBFBD>࣬<EFBFBD><EFBFBD>ҪΪ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ܡ<EFBFBD>
|
|
|
|
|
* redis client network IO class. The redis request is sent to server
|
|
|
|
|
* and the server's respond is handled in this class. The class inherits
|
|
|
|
|
* connect_client, which can use the connection pool function.
|
|
|
|
|
*/
|
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
|
|
|
|
|
2015-02-13 22:52:43 +08:00
|
|
|
|
socket_stream* get_stream();
|
2015-01-26 19:58:02 +08:00
|
|
|
|
|
2015-02-13 22:52:43 +08:00
|
|
|
|
void set_slice_request(bool on);
|
|
|
|
|
void set_slice_respond(bool on);
|
2015-01-14 23:35:23 +08:00
|
|
|
|
|
2015-02-13 22:52:43 +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_;
|
2015-02-13 22:52:43 +08:00
|
|
|
|
bool slice_req_;
|
|
|
|
|
bool slice_res_;
|
2015-01-21 23:39:02 +08:00
|
|
|
|
|
2015-02-13 22:52:43 +08:00
|
|
|
|
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
|
|
|
|
|
2015-02-13 22:52:43 +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
|