2019-07-27 22:44:32 +08:00
|
|
|
|
#pragma once
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
|
|
|
|
#include "redis_command.hpp"
|
2015-01-19 00:03:30 +08:00
|
|
|
|
|
2019-05-19 16:54:20 +08:00
|
|
|
|
#if !defined(ACL_CLIENT_ONLY) && !defined(ACL_REDIS_DISABLE)
|
2019-05-18 21:19:21 +08:00
|
|
|
|
|
2015-01-19 00:03:30 +08:00
|
|
|
|
namespace acl
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class redis_client;
|
|
|
|
|
|
2015-01-26 19:58:02 +08:00
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* redis Connection 类,包含命令如下:
|
|
|
|
|
* AUTH、ECHO、PING、QUIT、SELECT
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* redis connection command clss, including as below:
|
|
|
|
|
* AUTH, ECHO, PING, QUIT, SELECT
|
2015-01-26 19:58:02 +08:00
|
|
|
|
*/
|
2015-03-27 17:05:12 +08:00
|
|
|
|
class ACL_CPP_API redis_connection : virtual public redis_command
|
2015-01-19 00:03:30 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
2015-03-29 19:27:41 +08:00
|
|
|
|
/**
|
|
|
|
|
* see redis_command::redis_command()
|
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
redis_connection(void);
|
2015-03-29 19:27:41 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* see redis_command::redis_command(redis_client*)
|
|
|
|
|
*/
|
2015-03-27 17:05:12 +08:00
|
|
|
|
redis_connection(redis_client* conn);
|
2015-03-29 19:27:41 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* see redis_command::redis_command(redis_client_cluster*, size_t)
|
2015-03-29 19:27:41 +08:00
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
redis_connection(redis_client_cluster* cluster, size_t max_conns = 0);
|
2015-03-29 19:27:41 +08:00
|
|
|
|
|
2016-01-17 13:35:12 +08:00
|
|
|
|
virtual ~redis_connection(void);
|
2015-01-19 00:03:30 +08:00
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2015-01-26 19:58:02 +08:00
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 连接至 redis-server 时进行身份验证
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* AUTH command to login the redis server.
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* @param passwd {const char*} 在 redis 配置文件中指定的认证密码
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* the password in redis-server configure
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* @return {bool} 身份认证是否成功,返回 false 表示认证失败或操作失败
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* return true if success, or false because auth failed or error.
|
2015-01-26 19:58:02 +08:00
|
|
|
|
*/
|
2015-01-19 00:03:30 +08:00
|
|
|
|
bool auth(const char* passwd);
|
2015-01-26 19:58:02 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 选择 redis-server 中的数据库 ID
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* SELECT command to select the DB id in redis-server
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* @param dbnum {int} redis 数据库 ID
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* the DB id
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* @return {bool} 操作是否成功
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* return true if success, or false for failed.
|
2015-01-26 19:58:02 +08:00
|
|
|
|
*/
|
2015-01-19 00:03:30 +08:00
|
|
|
|
bool select(int dbnum);
|
2015-01-26 19:58:02 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 探测 redis 连接是否正常
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* PING command for testing if the connection is OK
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* @return {bool} 连接是否正常
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* return true if success
|
2015-01-26 19:58:02 +08:00
|
|
|
|
*/
|
2015-01-19 00:03:30 +08:00
|
|
|
|
bool ping();
|
2015-01-26 19:58:02 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 测试用命令,让 redis-server 回显给定字符串
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* ECHO command, request redis-server to echo something.
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* @return {bool} 操作是否成功
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* return true if success
|
2015-01-26 19:58:02 +08:00
|
|
|
|
*/
|
2015-01-19 00:03:30 +08:00
|
|
|
|
bool echo(const char* s);
|
2015-01-26 19:58:02 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-27 22:44:32 +08:00
|
|
|
|
* 关闭 redis 连接
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* QUIT command to close the redis connection
|
2015-01-26 19:58:02 +08:00
|
|
|
|
* @return {bool}
|
2015-03-29 19:27:41 +08:00
|
|
|
|
* return true if success
|
2015-01-26 19:58:02 +08:00
|
|
|
|
*/
|
2015-01-19 00:03:30 +08:00
|
|
|
|
bool quit();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|
2019-05-18 21:19:21 +08:00
|
|
|
|
|
2019-05-19 16:54:20 +08:00
|
|
|
|
#endif // !defined(ACL_CLIENT_ONLY) && !defined(ACL_REDIS_DISABLE)
|