Manages a connection pool, using a Redis Sentinel to get instaces ip, managing also failover.
More...
#include <connection_pool.h>
|
| 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 ptr_t | create (const std::string &sentinel_host, const std::string &master_name, unsigned int sentinel_port=26379) |
| | Create a new connection_pool. More...
|
| |
Manages a connection pool, using a Redis Sentinel to get instaces ip, managing also failover.
| 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_host | Can be a single host or a list separate by commas, if an host has multiple IPs, connection_pool tries all of them |
| master_name | Master to lookup |
| sentinel_port | Sentinel port, default 26379 |
- Returns
| connection::ptr_t connection_pool::get |
( |
connection::role_t |
type = connection::MASTER | ) |
|
Ask for a connection.
- Parameters
-
| type | Specify 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
-
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
-
| f | function to run, C++11 lambdas are perfect |
| conn_type | type of connection required |
| retries | how 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
-
| value | A valid database index |
The documentation for this class was generated from the following files: