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;
|
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-14 23:35:23 +08:00
|
|
|
|
dbuf_pool* get_pool() const
|
|
|
|
|
{
|
|
|
|
|
return pool_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
2014-11-19 00:25:21 +08:00
|
|
|
|
void close();
|
2015-01-14 23:35:23 +08:00
|
|
|
|
|
2015-01-19 00:03:30 +08:00
|
|
|
|
const redis_result* run(const string& request, size_t nobjs = 1);
|
2015-01-14 23:35:23 +08:00
|
|
|
|
|
|
|
|
|
const string& build_request(size_t argc, const char* argv[],
|
|
|
|
|
size_t argv_lens[], string* buf = NULL);
|
|
|
|
|
|
2015-01-19 00:03:30 +08:00
|
|
|
|
const string& build_request(const std::vector<string>& args,
|
|
|
|
|
string* buf = NULL);
|
|
|
|
|
const string& build_request(const std::vector<const char*>& args,
|
|
|
|
|
const std::vector<size_t>& lens, string* buf = NULL);
|
|
|
|
|
|
2015-01-14 23:35:23 +08:00
|
|
|
|
/*******************************************************************/
|
|
|
|
|
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::map<string, string>& attrs, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::map<string, char*>& attrs, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::map<string, const char*>& attrs, string* buf = NULL);
|
|
|
|
|
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::map<int, string>& attrs, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::map<int, char*>& attrs, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::map<int, const char*>& attrs, string* buf = NULL);
|
|
|
|
|
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::vector<string>& names,
|
|
|
|
|
const std::vector<string>& values, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::vector<char*>& names,
|
|
|
|
|
const std::vector<char*>& values, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::vector<const char*>& names,
|
|
|
|
|
const std::vector<const char*>& values, string* buf = NULL);
|
|
|
|
|
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::vector<int>& names,
|
|
|
|
|
const std::vector<string>& values, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::vector<int>& names,
|
|
|
|
|
const std::vector<char*>& values, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::vector<int>& names,
|
|
|
|
|
const std::vector<const char*>& values, string* buf = NULL);
|
|
|
|
|
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const char* names[], const char* values[], size_t argc,
|
|
|
|
|
string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const int names[], const char* values[], size_t argc,
|
|
|
|
|
string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const char* names[], const size_t names_len[],
|
|
|
|
|
const char* values[], const size_t values_len[],
|
|
|
|
|
size_t argc, string* buf = NULL);
|
|
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
|
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::vector<string>& names, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::vector<char*>& names, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::vector<const char*>& names, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const std::vector<int>& names, string* buf = NULL);
|
|
|
|
|
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const char* names[], size_t argc, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const int names[], size_t argc, string* buf = NULL);
|
|
|
|
|
const string& build(const char* cmd, const char* key,
|
|
|
|
|
const char* names[], const size_t lens[],
|
|
|
|
|
size_t argc, string* buf = NULL);
|
|
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>麯<EFBFBD><E9BAAF>
|
|
|
|
|
virtual bool open();
|
|
|
|
|
|
2014-11-19 00:25:21 +08:00
|
|
|
|
private:
|
2015-01-14 23:35:23 +08:00
|
|
|
|
unsigned long long used_;
|
|
|
|
|
dbuf_pool* pool_;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
socket_stream conn_;
|
|
|
|
|
char* addr_;
|
|
|
|
|
int conn_timeout_;
|
|
|
|
|
int rw_timeout_;
|
|
|
|
|
bool retry_;
|
2015-01-14 23:35:23 +08:00
|
|
|
|
size_t argv_size_;
|
|
|
|
|
const char** argv_;
|
|
|
|
|
size_t argc_;
|
|
|
|
|
size_t* argv_lens_;
|
|
|
|
|
string request_;
|
|
|
|
|
string buf_;
|
|
|
|
|
redis_result* result_;
|
|
|
|
|
|
|
|
|
|
void argv_space(size_t n);
|
|
|
|
|
|
2015-01-19 00:03:30 +08:00
|
|
|
|
redis_result* get_objects(size_t nobjs);
|
2015-01-14 23:35:23 +08:00
|
|
|
|
redis_result* get_object();
|
|
|
|
|
redis_result* get_error();
|
|
|
|
|
redis_result* get_status();
|
|
|
|
|
redis_result* get_integer();
|
|
|
|
|
redis_result* get_string();
|
|
|
|
|
redis_result* get_array();
|
2014-11-19 00:25:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end namespace acl
|