cpp_redis  4.0.0
cpp_redis is a C++11 Asynchronous Multi-Platform Lightweight Redis Client, with support for synchronous operations and pipelining.
Public Types | Public Member Functions | List of all members
cpp_redis::network::redis_connection Class Reference

#include <redis_connection.hpp>

Public Types

typedef std::function< void(redis_connection &)> disconnection_handler_t
 
typedef std::function< void(redis_connection &, reply &)> reply_callback_t
 

Public Member Functions

 redis_connection (void)
 ctor
 
 redis_connection (const std::shared_ptr< tcp_client_iface > &tcp_client)
 
 ~redis_connection (void)
 dtor
 
 redis_connection (const redis_connection &)=delete
 copy ctor
 
redis_connectionoperator= (const redis_connection &)=delete
 assignment operator
 
void connect (const std::string &host="127.0.0.1", std::size_t port=6379, const disconnection_handler_t &disconnection_handler=nullptr, const reply_callback_t &reply_callback=nullptr, std::uint32_t timeout_msecs=0)
 
void disconnect (bool wait_for_removal=false)
 
bool is_connected (void) const
 
redis_connectionsend (const std::vector< std::string > &redis_cmd)
 
redis_connectioncommit (void)
 

Detailed Description

tcp connection wrapper handling redis protocol

Member Typedef Documentation

◆ disconnection_handler_t

disconnection handler takes as parameter the instance of the redis_connection

◆ reply_callback_t

reply handler takes as parameter the instance of the redis_connection and the built reply

Constructor & Destructor Documentation

◆ redis_connection()

cpp_redis::network::redis_connection::redis_connection ( const std::shared_ptr< tcp_client_iface > &  tcp_client)
explicit

ctor allowing to specify custom tcp client (default ctor uses the default tacopie tcp client)

Parameters
tcp_clienttcp client to be used for network communications

Member Function Documentation

◆ commit()

redis_connection& cpp_redis::network::redis_connection::commit ( void  )

commit pipelined transaction that is, send to the network all commands pipelined by calling send()

Returns
current instance

◆ connect()

void cpp_redis::network::redis_connection::connect ( const std::string &  host = "127.0.0.1",
std::size_t  port = 6379,
const disconnection_handler_t disconnection_handler = nullptr,
const reply_callback_t reply_callback = nullptr,
std::uint32_t  timeout_msecs = 0 
)

connect to the given host and port, and set both disconnection and reply callbacks

Parameters
hosthost to be connected to
portport to be connected to
disconnection_handlerhandler to be called in case of disconnection
reply_callbackhandler to be called once a reply is ready
timeout_msecsmax time to connect (in ms)

◆ disconnect()

void cpp_redis::network::redis_connection::disconnect ( bool  wait_for_removal = false)

disconnect from redis server

Parameters
wait_for_removalwhen 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.

◆ is_connected()

bool cpp_redis::network::redis_connection::is_connected ( void  ) const
Returns
whether we are connected to the redis server or not

◆ send()

redis_connection& cpp_redis::network::redis_connection::send ( const std::vector< std::string > &  redis_cmd)

send the given command the command is actually pipelined and only buffered, so nothing is sent to the network please call commit() to flush the buffer

Parameters
redis_cmdcommand to be sent
Returns
current instance

The documentation for this class was generated from the following file: