Showing content from https://cylix.github.io/cpp_redis/html/classcpp__redis_1_1subscriber.html below:
cpp_redis: cpp_redis::subscriber Class Reference
#include <subscriber.hpp>
subscriber (void) ctor
subscriber (const std::shared_ptr< network::tcp_client_iface > &tcp_client) ~subscriber (void) dtor
subscriber (const subscriber &)=delete copy ctor
subscriber & operator= (const subscriber &)=delete assignment operator
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_msecs=0, std::int32_t max_reconnects=0, std::uint32_t reconnect_interval_msecs=0) void connect (const std::string &name, const connect_callback_t &connect_callback=nullptr, std::uint32_t timeout_msecs=0, std::int32_t max_reconnects=0, std::uint32_t reconnect_interval_msecs=0) bool is_connected (void) const void disconnect (bool wait_for_removal=false) bool is_reconnecting (void) const void cancel_reconnect (void) subscriber & auth (const std::string &password, const reply_callback_t &reply_callback=nullptr) subscriber & subscribe (const std::string &channel, const subscribe_callback_t &callback, const acknowledgement_callback_t &acknowledgement_callback=nullptr) subscriber & psubscribe (const std::string &pattern, const subscribe_callback_t &callback, const acknowledgement_callback_t &acknowledgement_callback=nullptr) subscriber & unsubscribe (const std::string &channel) subscriber & punsubscribe (const std::string &pattern) subscriber & commit (void) void add_sentinel (const std::string &host, std::size_t port, std::uint32_t timeout_msecs=0) const sentinel & get_sentinel (void) const sentinel & get_sentinel (void) void clear_sentinels (void)
The cpp_redis::subscriber is meant to be used for PUB/SUB communication with the Redis server. Please do not use cpp_redis::client to subscribe to some Redis channels as:
◆ acknowledgement_callback_t
acknowledgement callback called whenever a subscribe completes takes as parameter the int returned by the redis server (usually the number of channels you are subscribed to)
◆ connect_callback_t
connect handler, called whenever a new connection even occurred
◆ reply_callback_t
reply callback called whenever a reply is received takes as parameter the received reply
◆ subscribe_callback_t
subscribe callback, called whenever a new message is published on a subscribed channel takes as parameter the channel and the message
◆ connect_state
high availability (re)connection states
- dropped: connection has dropped
- start: attemp of connection has started
- sleeping: sleep between two attemps
- ok: connected
- failed: failed to connect
- lookup failed: failed to retrieve master sentinel
- stopped: stop to try to reconnect
◆ subscriber()
custom ctor to specify custom tcp_client
-
Parameters
-
tcp_client tcp client to be used for network communications
◆ add_sentinel() void cpp_redis::subscriber::add_sentinel ( const std::string & host, std::size_t port, std::uint32_t timeout_msecs = 0
)
add a sentinel definition. Required for connect() or get_master_addr_by_name() when autoconnect is enabled.
-
Parameters
-
host sentinel host port sentinel port timeout_msecs maximum time to connect
◆ auth()
ability to authenticate on the redis server if necessary this method should not be called repeatedly as the storage of reply_callback is NOT threadsafe (only one reply callback is stored for the subscriber client) calling repeatedly auth() is undefined concerning the execution of the associated callbacks
-
Parameters
-
password password to be used for authentication reply_callback callback to be called on auth completion (nullable)
-
Returns
-
current instance
◆ cancel_reconnect() void cpp_redis::subscriber::cancel_reconnect ( void )
stop any reconnect in progress
◆ clear_sentinels() void cpp_redis::subscriber::clear_sentinels ( void )
clear all existing sentinels.
◆ commit() subscriber& cpp_redis::subscriber::commit ( void )
commit pipelined transaction that is, send to the network all commands pipelined by calling send() / subscribe() / ...
-
Returns
-
current instance
◆ connect() [1/2] void cpp_redis::subscriber::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_msecs = 0
, std::int32_t max_reconnects = 0
, std::uint32_t reconnect_interval_msecs = 0
)
Connect to redis server
-
Parameters
-
host host to be connected to port port to be connected to connect_callback connect handler to be called on connect events (may be null) timeout_msecs maximum time to connect max_reconnects maximum attemps of reconnection if connection dropped reconnect_interval_msecs time between two attemps of reconnection
◆ connect() [2/2] void cpp_redis::subscriber::connect ( const std::string & name, const connect_callback_t & connect_callback = nullptr
, std::uint32_t timeout_msecs = 0
, std::int32_t max_reconnects = 0
, std::uint32_t reconnect_interval_msecs = 0
)
Connect to redis server
-
Parameters
-
name sentinel name connect_callback connect handler to be called on connect events (may be null) timeout_msecs maximum time to connect max_reconnects maximum attemps of reconnection if connection dropped reconnect_interval_msecs time between two attemps of reconnection
◆ disconnect() void cpp_redis::subscriber::disconnect ( bool wait_for_removal = false
)
disconnect from redis server
-
Parameters
-
wait_for_removal when sets to true, disconnect blocks until the underlying TCP client has been effectively removed from the io_service and that all the underlying callbacks have completed.
◆ get_sentinel() [1/2] const sentinel& cpp_redis::subscriber::get_sentinel ( void ) const
retrieve sentinel for current client
-
Returns
-
sentinel associated to current client
◆ get_sentinel() [2/2] sentinel& cpp_redis::subscriber::get_sentinel ( void )
retrieve sentinel for current client non-const version
-
Returns
-
sentinel associated to current client
◆ is_connected() bool cpp_redis::subscriber::is_connected ( void ) const
-
Returns
-
whether we are connected to the redis server
◆ is_reconnecting() bool cpp_redis::subscriber::is_reconnecting ( void ) const
-
Returns
-
whether an attemp to reconnect is in progress
◆ psubscribe()
PSubscribes to the given channel and:
- calls acknowledgement_callback once the server has acknowledged about the subscription.
- calls subscribe_callback each time a message is published on this channel. The command is not effectively sent immediately but stored in an internal buffer until commit() is called.
-
Parameters
-
pattern pattern to psubscribe callback callback to be called whenever a message is received for this pattern acknowledgement_callback callback to be called on subscription completion (nullable)
-
Returns
-
current instance
◆ punsubscribe() subscriber& cpp_redis::subscriber::punsubscribe ( const std::string & pattern )
punsubscribe from the given pattern The command is not effectively sent immediately, but stored inside an internal buffer until commit() is called.
-
Parameters
-
pattern pattern to punsubscribe from
-
Returns
-
current instance
◆ subscribe()
Subscribes to the given channel and:
- calls acknowledgement_callback once the server has acknowledged about the subscription.
- calls subscribe_callback each time a message is published on this channel. The command is not effectively sent immediately but stored in an internal buffer until commit() is called.
-
Parameters
-
channel channel to subscribe callback callback to be called whenever a message is received for this channel acknowledgement_callback callback to be called on subscription completion (nullable)
-
Returns
-
current instance
◆ unsubscribe() subscriber& cpp_redis::subscriber::unsubscribe ( const std::string & channel )
unsubscribe from the given channel The command is not effectively sent immediately, but stored inside an internal buffer until commit() is called.
-
Parameters
-
channel channel to unsubscribe from
-
Returns
-
current instance
The documentation for this class was generated from the following file:
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4