2019-07-27 22:44:32 +08:00
|
|
|
|
#pragma once
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
2015-06-03 11:19:13 +08:00
|
|
|
|
#include <map>
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../stdlib/string.hpp"
|
|
|
|
|
#include "session.hpp"
|
2015-06-03 11:19:13 +08:00
|
|
|
|
|
2019-05-18 21:19:21 +08:00
|
|
|
|
#ifndef ACL_CLIENT_ONLY
|
|
|
|
|
|
2015-06-03 11:19:13 +08:00
|
|
|
|
namespace acl
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class redis;
|
|
|
|
|
class redis_client_cluster;
|
|
|
|
|
|
|
|
|
|
class ACL_CPP_API redis_session : public session
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
redis_session(redis_client_cluster& cluster, size_t max_conns,
|
|
|
|
|
time_t ttl = 0, const char* sid = NULL);
|
|
|
|
|
~redis_session();
|
|
|
|
|
|
2019-07-27 22:44:32 +08:00
|
|
|
|
// 基类虚函数,向 redis 服务端设置哈希属性值
|
2015-06-03 11:19:13 +08:00
|
|
|
|
bool set(const char* name, const char* value);
|
|
|
|
|
|
2019-07-27 22:44:32 +08:00
|
|
|
|
// 基类虚函数,向 redis 服务端设置哈希属性值
|
2015-06-03 11:19:13 +08:00
|
|
|
|
bool set(const char* name, const void* value, size_t len);
|
|
|
|
|
|
2019-07-27 22:44:32 +08:00
|
|
|
|
// 基类虚函数,从 redis 服务端的哈希对象中获得对应属性的值
|
2015-06-03 11:19:13 +08:00
|
|
|
|
const session_string* get_buf(const char* name);
|
|
|
|
|
|
2019-07-27 22:44:32 +08:00
|
|
|
|
// 基类虚函数,从 redis 服务端的哈希对象中删除某个属性值
|
2015-06-03 11:19:13 +08:00
|
|
|
|
bool del(const char* name);
|
|
|
|
|
|
2019-07-27 22:44:32 +08:00
|
|
|
|
// 基类纯虚函数,从 redis 中删除数据
|
2015-06-03 11:19:13 +08:00
|
|
|
|
bool remove();
|
|
|
|
|
|
2019-07-27 22:44:32 +08:00
|
|
|
|
// 基类纯虚函数,从 redis 中获得数据
|
2015-06-03 11:19:13 +08:00
|
|
|
|
bool get_attrs(std::map<string, session_string>& attrs);
|
|
|
|
|
|
2019-07-27 22:44:32 +08:00
|
|
|
|
// 基类虚函数,从 redis 中获得数据
|
2016-02-25 19:57:02 +08:00
|
|
|
|
bool get_attrs(const std::vector<string>& names,
|
|
|
|
|
std::vector<session_string>& values);
|
|
|
|
|
|
2019-07-27 22:44:32 +08:00
|
|
|
|
// 基类纯虚函数,向 redis 中添加或修改数据
|
2015-06-03 11:19:13 +08:00
|
|
|
|
bool set_attrs(const std::map<string, session_string>& attrs);
|
|
|
|
|
|
|
|
|
|
protected:
|
2019-07-27 22:44:32 +08:00
|
|
|
|
//重新设置 session 在 redis 上的缓存时间
|
2015-06-03 11:19:13 +08:00
|
|
|
|
bool set_timeout(time_t ttl);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
redis_client_cluster& cluster_;
|
|
|
|
|
redis* command_;
|
2017-07-20 10:59:28 +08:00
|
|
|
|
// size_t max_conns_;
|
2015-06-03 22:41:24 +08:00
|
|
|
|
std::map<string, session_string*> buffers_;
|
2015-06-03 11:19:13 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|
2019-05-18 21:19:21 +08:00
|
|
|
|
|
|
|
|
|
#endif // ACL_CLIENT_ONLY
|