诸暨麻将添加redis
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

36 lines
1.0 KiB

  1. #include "stdafx.h"
  2. #include "RedisHead.h"
  3. RedisBase::RedisBase()
  4. {
  5. }
  6. RedisBase::~RedisBase()
  7. {
  8. }
  9. //Á¬½Óredis
  10. 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*/)
  11. {
  12. winsock_initializer winsock_init;
  13. m_redisclient = std::make_shared<cpp_redis::client>();
  14. m_redisclient->connect(host, port,
  15. [](const std::string& host, std::size_t port, cpp_redis::connect_state status) {
  16. if (status == cpp_redis::connect_state::dropped) {
  17. std::cout << "client disconnected from " << host << ":" << port << std::endl;
  18. }
  19. }, timeout_ms, max_reconnects, reconnect_interval_ms);
  20. m_redisclient->select(db);
  21. m_redisclient->disconnect(true);
  22. return true;
  23. }
  24. void RedisBase::DisConnect(bool wait_for_removal/*= false*/ ){
  25. m_redisclient->disconnect(wait_for_removal);
  26. }
  27. std::shared_ptr<cpp_redis::client> RedisBase::GetRedisClient()
  28. {
  29. return m_redisclient;
  30. }