redis3m  1.0.0
 All Classes Functions Variables Enumerations Pages
Public Types | Public Member Functions | Static Public Member Functions | List of all members
redis3m::connection_pool Class Reference

Manages a connection pool, using a Redis Sentinel to get instaces ip, managing also failover. More...

#include <connection_pool.h>

Inheritance diagram for redis3m::connection_pool:

Public Types

typedef boost::shared_ptr
< connection_pool
ptr_t
 

Public Member Functions

connection::ptr_t get (connection::role_t type=connection::MASTER)
 Ask for a connection. More...
 
void put (connection::ptr_t conn)
 Put a connection again on pool for reuse, pay attention to insert only connection created from the same pool. Otherwise unpexpected behaviours can happen. More...
 
template<typename Ret >
Ret run_with_connection (boost::function< Ret(connection::ptr_t)> f, connection::role_t conn_type=connection::MASTER, unsigned int retries=5)
 Execute a block of code passing a connection::ptr_t if something fails, like broken connection, it will automatically retry with an another one. More...
 
void set_database (unsigned int value)
 Set a database to use on every new connection object created by the pool. More...
 
template<>
void run_with_connection (boost::function< void(connection::ptr_t)> f, connection::role_t conn_type, unsigned int retries)
 

Static Public Member Functions

static ptr_t create (const std::string &sentinel_host, const std::string &master_name, unsigned int sentinel_port=26379)
 Create a new connection_pool. More...
 

Detailed Description

Manages a connection pool, using a Redis Sentinel to get instaces ip, managing also failover.

Member Function Documentation

static ptr_t redis3m::connection_pool::create ( const std::string &  sentinel_host,
const std::string &  master_name,
unsigned int  sentinel_port = 26379 
)
inlinestatic

Create a new connection_pool.

Parameters
sentinel_hostCan be a single host or a list separate by commas, if an host has multiple IPs, connection_pool tries all of them
master_nameMaster to lookup
sentinel_portSentinel port, default 26379
Returns
connection::ptr_t connection_pool::get ( connection::role_t  type = connection::MASTER)

Ask for a connection.

Parameters
typeSpecify the type required, Master, Slave or Any
Returns
a valid connection object
void connection_pool::put ( connection::ptr_t  conn)

Put a connection again on pool for reuse, pay attention to insert only connection created from the same pool. Otherwise unpexpected behaviours can happen.

Parameters
conn
template<typename Ret >
Ret redis3m::connection_pool::run_with_connection ( boost::function< Ret(connection::ptr_t)>  f,
connection::role_t  conn_type = connection::MASTER,
unsigned int  retries = 5 
)
inline

Execute a block of code passing a connection::ptr_t if something fails, like broken connection, it will automatically retry with an another one.

Parameters
ffunction to run, C++11 lambdas are perfect
conn_typetype of connection required
retrieshow much retries do
Returns
void redis3m::connection_pool::set_database ( unsigned int  value)
inline

Set a database to use on every new connection object created by the pool.

Parameters
valueA valid database index

The documentation for this class was generated from the following files: