31 #include <cpp_redis/core/sentinel.hpp> 32 #include <cpp_redis/network/redis_connection.hpp> 33 #include <cpp_redis/network/tcp_client_iface.hpp> 45 #ifndef __CPP_REDIS_USE_CUSTOM_TCP_CLIENT 57 explicit subscriber(
const std::shared_ptr<network::tcp_client_iface> &tcp_client);
91 typedef std::function<void(const std::string &host, std::size_t port, connect_state status)>
connect_callback_t;
101 const std::string &host =
"127.0.0.1",
102 std::size_t port = 6379,
104 std::uint32_t timeout_ms = 0,
105 std::int32_t max_reconnects = 0,
106 std::uint32_t reconnect_interval_ms = 0);
115 const std::string &m_name,
117 std::uint32_t timeout_ms = 0,
118 std::int32_t max_reconnects = 0,
119 std::uint32_t reconnect_interval_ms = 0);
127 void disconnect(
bool wait_for_removal =
false);
152 typedef std::function<void(const std::string &, const std::string &)>
read_callback_t;
222 void add_sentinel(
const std::string &host, std::size_t port, std::uint32_t timeout_ms = 0);
248 struct callback_holder {
275 void handle_acknowledgement_reply(
const std::vector<reply> &
reply);
283 void read_reply_handler(
const std::vector<reply> &
reply);
291 void handle_psubscribe_reply(
const std::vector<reply> &
reply);
302 call_acknowledgement_callback(
const std::string &channel,
const std::map<std::string, callback_holder> &channels,
303 std::mutex &channels_mtx, int64_t nb_chans);
325 bool should_reconnect()
const;
330 void sleep_before_next_reconnect_attempt();
335 void clear_subscriptions();
346 void unprotected_read(
const std::string &channel,
const read_callback_t &callback,
357 void unprotected_psubscribe(
const std::string &pattern,
const read_callback_t &callback,
364 std::string m_redis_server;
368 std::size_t m_redis_port = 0;
372 std::string m_master_name;
376 std::string m_password;
391 std::uint32_t m_connect_timeout_ms = 0;
395 std::int32_t m_max_reconnects = 0;
399 std::int32_t m_current_reconnect_attempts = 0;
403 std::uint32_t m_reconnect_interval_ms = 0;
408 std::atomic_bool m_reconnecting;
412 std::atomic_bool m_cancel;
417 std::map<std::string, callback_holder> m_subscribed_sessions;
421 std::map<std::string, callback_holder> m_psubscribed_channels;
431 std::mutex m_psubscribed_channels_mutex;
435 std::mutex m_subscribed_sessions_mutex;
Definition: redis_connection.hpp:45
Definition: subscriber.hpp:43
const sentinel & get_sentinel() const
std::function< void(const std::string &host, std::size_t port, connect_state status)> connect_callback_t
connect handler, called whenever a new connection even occurred
Definition: subscriber.hpp:91
subscriber & psubscribe(const std::string &pattern, const read_callback_t &callback, const acknowledgement_callback_t &acknowledgement_callback=nullptr)
void cancel_reconnect()
stop any reconnect in progress
subscriber & operator=(const subscriber &)=delete
assignment operator
bool is_connected() const
determines client connectivity
bool is_reconnecting() const
determines if reconnect is in progress
std::function< void(int64_t)> acknowledgement_callback_t
Definition: subscriber.hpp:158
connect_state
Definition: subscriber.hpp:79
std::function< void(const std::string &, const std::string &)> read_callback_t
Definition: subscriber.hpp:152
subscriber & auth(const std::string &password, const reply_callback_t &reply_callback=nullptr)
ability to authenticate on the redis server if necessary this method should not be called repeatedly ...
Definition: sentinel.hpp:40
void add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_ms=0)
void disconnect(bool wait_for_removal=false)
disconnect from redis server
subscriber & punsubscribe(const std::string &pattern)
subscriber & unsubscribe(const std::string &channel)
void connect(const std::string &host="127.0.0.1", std::size_t port=6379, const connect_callback_t &connect_callback=nullptr, std::uint32_t timeout_ms=0, std::int32_t max_reconnects=0, std::uint32_t reconnect_interval_ms=0)
Connect to redis server.
std::function< void(reply &)> reply_callback_t
reply callback called whenever a reply is received, takes as parameter the received reply ...
Definition: subscriber.hpp:138
subscriber & subscribe(const std::string &channel, const read_callback_t &callback, const acknowledgement_callback_t &acknowledgement_callback=nullptr)
Definition: array_builder.hpp:29