|
- #include "stdafx.h"
- #include "RedisHead.h"
-
- RedisBase::RedisBase()
- {
- }
-
- RedisBase::~RedisBase()
- {
- }
-
- //Á¬½Óredis
- bool RedisBase::Connect(const std::string& host /*= "127.0.0.1"*/, std::size_t port /*= 6379*/, std::uint32_t db /*=0*/, std::uint32_t timeout_ms /*= 0*/, std::int32_t max_reconnects /*= 0*/, std::uint32_t reconnect_interval_ms /*= 0*/)
- {
- winsock_initializer winsock_init;
- m_redisclient = std::make_shared<cpp_redis::client>();
- m_redisclient->connect(host, port,
- [](const std::string& host, std::size_t port, cpp_redis::connect_state status) {
- if (status == cpp_redis::connect_state::dropped) {
- std::cout << "client disconnected from " << host << ":" << port << std::endl;
- }
- }, timeout_ms, max_reconnects, reconnect_interval_ms);
- m_redisclient->select(db);
- m_redisclient->disconnect(true);
- return true;
- }
-
- void RedisBase::DisConnect(bool wait_for_removal/*= false*/ ){
- m_redisclient->disconnect(wait_for_removal);
- }
-
- std::shared_ptr<cpp_redis::client> RedisBase::GetRedisClient()
- {
- return m_redisclient;
- }
|