the new redis client can be compiled by vc2003

This commit is contained in:
ubuntu14 2015-02-02 07:52:11 -08:00
parent d4e5726585
commit 68ce4a101b
7 changed files with 392 additions and 6 deletions

View File

@ -8,6 +8,7 @@ namespace acl
{
class redis_client;
class redis_result;
class ACL_CPP_API redis_server : public redis_command
{
@ -17,27 +18,175 @@ public:
/////////////////////////////////////////////////////////////////////
/**
* AOF文件 AOF
* 使 BGREWRITEAOF AOF
* BGREWRITEAOF
* @return {bool}
*/
bool bgrewriteaof();
/**
* (Asynchronously)BGSAVE
* OK Redis fork Redis ()
* 退
* LASTSAVE BGSAVE
* @return {bool}
*/
bool bgsave();
/**
* CLIENT SETNAME
* @param buf {string&}
* @return {bool} false
*/
bool client_getname(string& buf);
/**
* ip:port
* @param addr {const char*} ip:port
* @return {bool} false
*/
bool client_kill(const char* addr);
/**
*
* @param buf {string&}
* @return {int} -1
*/
int client_list(string& buf);
/**
* CLIENT LIST
* Redis debug
* @param name {const char*}
* @return {bool}
*/
bool client_setname(const char* name);
/**
* Redis
* @param parameter {const char*}
* @param out {std::map<string, string>&} name-value
* parameter
* @return {int} "参数-值" -1
*/
int config_get(const char* parameter, std::map<string, string>& out);
/**
* INFO
* @return {bool}
*/
bool config_resetstat();
/**
* Redis redis.conf
* @return {bool}
*/
bool config_rewrite();
/**
* Redis
* @param name {const char*}
* @param value {const char*}
* @return {bool}
*/
bool config_set(const char* name, const char* value);
/**
* key
* @return {int} -1
*/
int dbsize();
/**
* Redis ( key )
* @return {bool}
*
*/
bool flushall();
/**
* key
* @return {bool}
*
*/
bool flushdb();
/**
* Redis
* @param buf {string&}
* @return {int}
*/
int info(string& buf);
/**
* Redis UNIX
* @return {time_t}
*/
time_t lastsave();
/**
* Redis ;
* get_command
* @return {bool}
*/
bool monitor();
/**
* monitor
* 便
* @param buf {string&}
* @return {bool}
*/
bool get_command(string& buf);
/**
* Redis (snapshot)
* RDB
* @return {bool}
*/
bool save();
/**
* 退
* @param save_data {bool} 退
*/
void shutdown(bool save_data = true);
/**
*
* @param ip {const char*} IP
* @param port {int}
* @return {bool}
*/
bool slaveof(const char* ip, int port);
/**
*
* @param number {int} 0
* @return {const redis_result*}
*/
const redis_result* slowlog_get(int number = 0);
/**
*
* @return {int}
*/
int slowlog_len();
/**
* slow log
* @return {bool}
*/
bool slowlog_reset();
/**
*
* @param stamp {time_t&} ( UNIX )
* @param escape {int*}
*/
bool get_time(time_t& stamp, int& escape);
};

View File

@ -12,7 +12,7 @@ class redis_client;
class redis_result;
/**
* PSETEX
*
*/
class ACL_CPP_API redis_string : public redis_command
{
@ -33,7 +33,7 @@ public:
const char* value, size_t value_len);
/**
* value key key seconds ()
* value key key timeout ()
* key SETEX
* @param key {const char*} key
* @param value {const char*} value
@ -44,6 +44,18 @@ public:
bool setex(const char* key, size_t key_len, const char* value,
size_t value_len, int timeout);
/**
* value key key timeout ()
* key SETEX
* @param key {const char*} key
* @param value {const char*} value
* @param timeout {int}
* @return {bool} false key
*/
bool psetex(const char* key, const char* value, int timeout);
bool psetex(const char* key, size_t key_len, const char* value,
size_t value_len, int timeout);
/**
* key value key key
* SETNX

View File

@ -345,6 +345,9 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
<File
RelativePath=".\src\stdlib\charset_conv.cpp">
</File>
<File
RelativePath=".\src\stdlib\dbuf_pool.cpp">
</File>
<File
RelativePath=".\src\stdlib\dns_service.cpp">
</File>
@ -721,9 +724,63 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
<Filter
Name="redis"
Filter="">
<File
RelativePath=".\src\redis\redic_connection.cpp">
</File>
<File
RelativePath=".\src\redis\redis_client.cpp">
</File>
<File
RelativePath=".\src\redis\redis_command.cpp">
</File>
<File
RelativePath=".\src\redis\redis_hash.cpp">
</File>
<File
RelativePath=".\src\redis\redis_hyperloglog.cpp">
</File>
<File
RelativePath=".\src\redis\redis_key.cpp">
</File>
<File
RelativePath=".\src\redis\redis_list.cpp">
</File>
<File
RelativePath=".\src\redis\redis_manager.cpp">
</File>
<File
RelativePath=".\src\redis\redis_pool.cpp">
</File>
<File
RelativePath=".\src\redis\redis_pubsub.cpp">
</File>
<File
RelativePath=".\src\redis\redis_request.cpp">
</File>
<File
RelativePath=".\src\redis\redis_request.hpp">
</File>
<File
RelativePath=".\src\redis\redis_result.cpp">
</File>
<File
RelativePath=".\src\redis\redis_script.cpp">
</File>
<File
RelativePath=".\src\redis\redis_server.cpp">
</File>
<File
RelativePath=".\src\redis\redis_set.cpp">
</File>
<File
RelativePath=".\src\redis\redis_string.cpp">
</File>
<File
RelativePath=".\src\redis\redis_transaction.cpp">
</File>
<File
RelativePath=".\src\redis\redis_zset.cpp">
</File>
</Filter>
<Filter
Name="session"
@ -862,6 +919,9 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
<File
RelativePath=".\include\acl_cpp\stdlib\charset_conv.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\stdlib\dbuf_pool.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\stdlib\dns_service.hpp">
</File>
@ -1149,11 +1209,53 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
<File
RelativePath=".\include\acl_cpp\redis\redis_client.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_command.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_connection.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_hash.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_hyperloglog.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_key.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_response.hpp">
RelativePath=".\include\acl_cpp\redis\redis_list.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_manager.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_pool.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_pubsub.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_result.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_script.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_server.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_set.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_string.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_transaction.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\redis\redis_zset.hpp">
</File>
</Filter>
<Filter

View File

@ -301,7 +301,7 @@ static void init(const char* cmd, bool check)
__big_data = (char*) malloc(__big_data_length);
for (size_t i = 0; i < __big_data_length; i++)
{
ch = i % 255;
ch = (char) i % 255;
__big_data[i] = ch;
md5.update(&ch, 1);
}

View File

@ -427,7 +427,7 @@ void rfc822::mkdate_cst(time_t t, char *buf, size_t size)
p->tm_sec,
offset);
#else
snprintf(buf, size, "%s, %02d %s %04d %02d:%02d:%02d %+05d (CST)",
safe_snprintf(buf, size, "%s, %02d %s %04d %02d:%02d:%02d %+05d (CST)",
wdays[p->tm_wday],
p->tm_mday,
months[p->tm_mon],

View File

@ -20,6 +20,18 @@ redis_server::~redis_server()
}
bool redis_server::bgrewriteaof()
{
const char* argv[1];
size_t lens[1];
argv[0] = "BGREWRITEAOF";
lens[0] = sizeof("BGREWRITEAOF") - 1;
conn_->build_request(1, argv, lens);
return conn_->get_status("Background");
}
bool redis_server::bgsave()
{
const char* argv[1];
@ -225,7 +237,7 @@ time_t redis_server::lastsave()
lens[0] = sizeof("LASTSAVE") - 1;
conn_->build_request(1, argv, lens);
return conn_->get_number64();
return (time_t) conn_->get_number64();
}
bool redis_server::monitor()
@ -308,6 +320,62 @@ bool redis_server::slaveof(const char* ip, int port)
return conn_->get_status();
}
const redis_result* redis_server::slowlog_get(int number /* = 0 */)
{
const char* argv[3];
size_t lens[3];
argv[0] = "SLOWLOG";
lens[0] = sizeof("SLOWLOG") - 1;
argv[1] = "GET";
lens[1] = sizeof("GET") - 1;
size_t argc = 2;
char buf[INT_LEN];
if (number > 0)
{
safe_snprintf(buf, sizeof(buf), "%d", number);
argv[2] = buf;
lens[2] = strlen(buf);
argc++;
}
conn_->build_request(argc, argv, lens);
return conn_->run();
}
int redis_server::slowlog_len()
{
const char* argv[2];
size_t lens[2];
argv[0] = "SLOWLOG";
lens[0] = sizeof("SLOWLOG") - 1;
argv[1] = "LEN";
lens[1] = sizeof("LEN") - 1;
conn_->build_request(2, argv, lens);
return conn_->get_number();
}
bool redis_server::slowlog_reset()
{
const char* argv[2];
size_t lens[2];
argv[0] = "SLOWLOG";
lens[0] = sizeof("SLOWLOG") - 1;
argv[1] = "RESET";
lens[1] = sizeof("RESET") - 1;
conn_->build_request(2, argv, lens);
return conn_->get_status();
}
bool redis_server::get_time(time_t& stamp, int& escape)
{
const char* argv[1];

View File

@ -37,8 +37,10 @@ bool redis_string::set(const char* key, size_t key_len,
argv[0] = "SET";
lens[0] = sizeof("SET") - 1;
argv[1] = key;
lens[1] = key_len;
argv[2] = value;
lens[2] = value_len;
@ -59,6 +61,36 @@ bool redis_string::setex(const char* key, size_t key_len, const char* value,
argv[0] = "SETEX";
lens[0] = sizeof("SETEX") - 1;
argv[1] = key;
lens[1] = key_len;
char buf[INT_LEN];
(void) safe_snprintf(buf, sizeof(buf), "%d", timeout);
argv[2] = buf;
lens[2] = strlen(buf);
argv[3] = value;
lens[3] = value_len;
conn_->build_request(4, argv, lens);
return conn_->get_status();
}
bool redis_string::psetex(const char* key, const char* value, int timeout)
{
return psetex(key, strlen(key), value, strlen(value), timeout);
}
bool redis_string::psetex(const char* key, size_t key_len, const char* value,
size_t value_len, int timeout)
{
const char* argv[4];
size_t lens[4];
argv[0] = "PSETEX";
lens[0] = sizeof("PSETEX") - 1;
argv[1] = key;
lens[1] = key_len;
@ -87,8 +119,10 @@ int redis_string::setnx(const char* key, size_t key_len,
argv[0] = "SETNX";
lens[0] = sizeof("SETNX") - 1;
argv[1] = key;
lens[1] = key_len;
argv[2] = value;
lens[2] = value_len;
@ -108,8 +142,10 @@ int redis_string::append(const char* key, const char* value, size_t size)
argv[0] = "APPEND";
lens[0] = sizeof("APPEND") - 1;
argv[1] = key;
lens[1] = strlen(key);
argv[2] = value;
lens[2] = size;
@ -129,6 +165,7 @@ bool redis_string::get(const char* key, size_t len, string& buf)
argv[0] = "GET";
lens[0] = sizeof("GET") - 1;
argv[1] = key;
lens[1] = len;
@ -148,6 +185,7 @@ const redis_result* redis_string::get(const char* key, size_t len)
argv[0] = "GET";
lens[0] = sizeof("GET") - 1;
argv[1] = key;
lens[1] = len;
@ -173,8 +211,10 @@ bool redis_string::getset(const char* key, size_t key_len,
argv[0] = "GETSET";
lens[0] = sizeof("GETSET") - 1;
argv[1] = key;
lens[1] = key_len;
argv[2] = value;
lens[2] = value_len;
@ -196,6 +236,7 @@ int redis_string::get_strlen(const char* key, size_t len)
argv[0] = "STRLEN";
lens[0] = sizeof("STRLEN") - 1;
argv[1] = key;
lens[1] = len;
@ -216,6 +257,7 @@ int redis_string::setrange(const char* key, size_t key_len, unsigned offset,
argv[0] = "SETRANGE";
lens[0] = sizeof("SETRANGE") - 1;
argv[1] = key;
lens[1] = key_len;
@ -244,6 +286,7 @@ bool redis_string::getrange(const char* key, size_t key_len,
argv[0] = "GETRANGE";
lens[0] = sizeof("GETRANGE") - 1;
argv[1] = key;
lens[1] = key_len;
@ -275,6 +318,7 @@ bool redis_string::setbit(const char* key, size_t len,
argv[0] = "SETBIT";
lens[0] = sizeof("SETBIT") - 1;
argv[1] = key;
lens[1] = len;
@ -303,6 +347,7 @@ bool redis_string::getbit(const char* key, size_t len,
argv[0] = "GETBIT";
lens[0] = sizeof("GETBIT") - 1;
argv[1] = key;
lens[1] = len;
@ -331,6 +376,7 @@ int redis_string::bitcount(const char* key, size_t len)
argv[0] = "BITCOUNT";
lens[0] = sizeof("BITCOUNT") - 1;
argv[1] = key;
lens[1] = len;
@ -350,6 +396,7 @@ int redis_string::bitcount(const char* key, size_t len, int start, int end)
argv[0] = "BITCOUNT";
lens[0] = sizeof("BITCOUNT") - 1;
argv[1] = key;
lens[1] = len;
@ -458,8 +505,10 @@ int redis_string::bitop(const char* op, const char* destkey,
argv[0] = "BITOP";
lens[0] = sizeof("BITOP") - 1;
argv[1] = op;
lens[1] = strlen(op);
argv[2] = destkey;
lens[2] = strlen(destkey);
@ -484,8 +533,10 @@ int redis_string::bitop(const char* op, const char* destkey,
argv[0] = "BITOP";
lens[0] = sizeof("BITOP") - 1;
argv[1] = op;
lens[1] = strlen(op);
argv[2] = destkey;
lens[2] = strlen(destkey);
@ -510,8 +561,10 @@ int redis_string::bitop(const char* op, const char* destkey,
argv[0] = "BITOP";
lens[0] = sizeof("BITOP") - 1;
argv[1] = op;
lens[1] = strlen(op);
argv[2] = destkey;
lens[2] = strlen(destkey);
@ -687,6 +740,7 @@ bool redis_string::incrbyfloat(const char* key, double inc,
argv[0] = "INCRBYFLOAT";
lens[0] = sizeof("INCRBYFLOAT") - 1;
argv[1] = key;
lens[1] = strlen(key);
@ -724,6 +778,7 @@ bool redis_string::incoper(const char* cmd, const char* key, long long int n,
argv[0] = cmd;
lens[0] = strlen(cmd);
argv[1] = key;
lens[1] = strlen(key);