Skip to content
This repository was archived by the owner on Apr 6, 2019. It is now read-only.
This repository was 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

@ashishsb95

Description

@ashishsb95

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions