Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

Suggest better approach for connect and reconnect(when disconnected by server). #205

Open
ashishsb95 opened this issue Oct 3, 2018 · 0 comments

Comments

@ashishsb95
Copy link

Bear minimum code

Connect and reconnect code

`void RedisUtil::connect_callback(const std::string& host,
std::size_t port,
cpp_redis::client::connect_state status){
if (status == cpp_redis::client::connect_state::dropped) {
std::unique_lockstd::mutex ulock(m_mutex);
m_con_var.wait(ulock,std::bind(&RedisUtil::is_client_available,this));
release();
while(intialize(host,port)){};
}
}

bool RedisUtil::intialize(const std::string &redis_host , const int redis_port ){
auto conn_call_wrap = std::bind( &RedisUtil::connect_callback,this,_1,_2,_3);
redis_client.connect(redis_host, redis_port,conn_call_wrap);
}`

Redis client get wrapper

           `std::lock_guard<std::mutex> guard(m_mutex);
	m_is_cli_avail = false;
	redis_client.get(key, getCallBack);
	redis_client.sync_commit();
	m_is_cli_avail = true;
	m_con_var.notify_one();`

I am looking for a better approach, any help will be gratefully welcome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant