redis3m  1.0.0
 All Classes Functions Variables Enumerations Pages
simple_pool.h
1 // Copyright (c) 2014 Luca Marturana. All rights reserved.
2 // Licensed under Apache 2.0, see LICENSE for details
3 
4 #pragma once
5 
6 #include <boost/noncopyable.hpp>
7 #include <redis3m/connection.h>
8 #include <boost/thread/mutex.hpp>
9 #include <set>
10 
11 namespace redis3m
12 {
13 
17 class simple_pool: boost::noncopyable
18 {
19 public:
20  typedef boost::shared_ptr<simple_pool> ptr_t;
21 
22  inline ptr_t create(const std::string& host, unsigned int port)
23  {
24  return ptr_t(new simple_pool(host, port));
25  }
26 
31  connection::ptr_t get();
32 
37  void put(connection::ptr_t conn);
38 
44  inline void set_database(unsigned int value) { _database = value; }
45 
46 private:
47  simple_pool(const std::string& host, unsigned int port);
48 
49  std::string _host;
50  unsigned int _port;
51  unsigned int _database;
52  std::set<connection::ptr_t> connections;
53  boost::mutex access_mutex;
54 };
55 }
Manages a pool of connections to a single Redis server.
Definition: simple_pool.h:17
void put(connection::ptr_t conn)
Put back a connection for reuse.
Definition: simple_pool.cpp:39
void set_database(unsigned int value)
Set default database, all connection will be initialized selecting this database. ...
Definition: simple_pool.h:44