mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-15 09:20:52 +08:00
102 lines
1.8 KiB
C++
102 lines
1.8 KiB
C++
#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
|
|
{
|
|
|
|
redis_connection::redis_connection()
|
|
: redis_command(NULL)
|
|
{
|
|
}
|
|
|
|
redis_connection::redis_connection(redis_client* conn)
|
|
: redis_command(conn)
|
|
{
|
|
}
|
|
|
|
redis_connection::redis_connection(redis_client_cluster* cluster, size_t max_conns)
|
|
: redis_command(cluster, max_conns)
|
|
{
|
|
}
|
|
|
|
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];
|
|
safe_snprintf(buf, sizeof(buf), "%d", dbnum);
|
|
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
|