2015-02-14 01:01:29 +08:00
|
|
|
#include "acl_stdafx.hpp"
|
|
|
|
#include "acl_cpp/stdlib/string.hpp"
|
|
|
|
#include "acl_cpp/stdlib/snprintf.hpp"
|
|
|
|
#include "acl_cpp/redis/redis_client.hpp"
|
|
|
|
#include "acl_cpp/redis/redis_connection.hpp"
|
|
|
|
|
|
|
|
namespace acl
|
|
|
|
{
|
|
|
|
|
2015-03-27 17:05:12 +08:00
|
|
|
redis_connection::redis_connection()
|
|
|
|
: redis_command(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
redis_connection::redis_connection(redis_client* conn)
|
2015-02-14 01:01:29 +08:00
|
|
|
: redis_command(conn)
|
|
|
|
{
|
2015-03-27 17:05:12 +08:00
|
|
|
}
|
2015-02-14 01:01:29 +08:00
|
|
|
|
2015-04-02 22:19:57 +08:00
|
|
|
redis_connection::redis_connection(redis_client_cluster* cluster, size_t max_conns)
|
2015-03-27 17:05:12 +08:00
|
|
|
: redis_command(cluster, max_conns)
|
|
|
|
{
|
2015-02-14 01:01:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
redis_connection::~redis_connection()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool redis_connection::auth(const char* passwd)
|
|
|
|
{
|
|
|
|
const char* argv[2];
|
|
|
|
size_t lens[2];
|
|
|
|
|
|
|
|
argv[0] = "AUTH";
|
|
|
|
lens[0] = sizeof("AUTH") - 1;
|
|
|
|
|
|
|
|
argv[1] = passwd;
|
|
|
|
lens[1] = strlen(passwd);
|
|
|
|
|
|
|
|
build_request(2, argv, lens);
|
|
|
|
return check_status();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool redis_connection::select(int dbnum)
|
|
|
|
{
|
|
|
|
const char* argv[2];
|
|
|
|
size_t lens[2];
|
|
|
|
|
|
|
|
argv[0] = "SELECT";
|
|
|
|
lens[0] = strlen(argv[0]);
|
|
|
|
|
|
|
|
char buf[21];
|
2015-03-29 19:27:41 +08:00
|
|
|
safe_snprintf(buf, sizeof(buf), "%d", dbnum);
|
2015-02-14 01:01:29 +08:00
|
|
|
argv[1] = buf;
|
|
|
|
lens[1] = strlen(argv[1]);
|
|
|
|
|
|
|
|
build_request(2, argv, lens);
|
|
|
|
return check_status();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool redis_connection::ping()
|
|
|
|
{
|
|
|
|
const char* argv[1];
|
|
|
|
size_t lens[1];
|
|
|
|
|
|
|
|
argv[0] = "PING";
|
|
|
|
lens[0] = strlen(argv[0]);
|
|
|
|
|
|
|
|
build_request(1, argv, lens);
|
|
|
|
return check_status("PONG");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool redis_connection::echo(const char* s)
|
|
|
|
{
|
|
|
|
const char* argv[2];
|
|
|
|
size_t lens[2];
|
|
|
|
|
|
|
|
argv[0] = "ECHO";
|
|
|
|
lens[0] = strlen(argv[0]);
|
|
|
|
|
|
|
|
argv[1] = s;
|
|
|
|
lens[1] = strlen(argv[1]);
|
|
|
|
|
|
|
|
string buf;
|
|
|
|
build_request(2, argv, lens);
|
|
|
|
return get_string(buf) >= 0 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool redis_connection::quit()
|
|
|
|
{
|
|
|
|
const char* argv[1];
|
|
|
|
size_t lens[1];
|
|
|
|
|
|
|
|
argv[0] = "QUIT";
|
|
|
|
lens[0] = strlen(argv[0]);
|
|
|
|
|
|
|
|
build_request(1, argv, lens);
|
|
|
|
return check_status();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace acl
|