This repository has been archived on 2026-04-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
short-link-backend/includes/database_service.hpp
2024-12-16 10:34:38 +01:00

28 lines
No EOL
867 B
C++

#ifndef DATABASE_SERVICE_HPP
#define DATABASE_SERVICE_HPP
#include <boost/asio/io_context.hpp>
#include <cstddef>
#include <boost/redis/connection.hpp>
#include <memory>
class DatabaseService {
public:
static DatabaseService& getInstance(boost::asio::io_context& io_context, std::size_t pool_size);
private:
std::shared_ptr<boost::redis::connection> getConnection(); //retrive a connection from the connection pool
DatabaseService(boost::asio::io_context& io_context, std::size_t pool_size = 4);
~DatabaseService();
DatabaseService(DatabaseService const&);
void operator=(DatabaseService const&);
boost::asio::io_context& io_context_;
std::size_t pool_size_;
std::vector<std::shared_ptr<boost::redis::connection>> connection_pool_;
std::size_t current_index_ = 0; //index used for round robin selection
};
#endif