1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-02-22 12:44:55 +00:00

Add constructor for opening connection to socket.

This commit is contained in:
King_DuckZ 2016-06-21 14:20:30 +01:00
parent c61619eb38
commit 29e2375e3b
2 changed files with 18 additions and 1 deletions

View file

@ -50,13 +50,24 @@ namespace redis {
{ {
} }
Command::Command (std::string&& parSocket) :
m_conn(nullptr, &redisAsyncDisconnect),
m_address(std::move(parSocket),
m_port(0)
{
}
Command::~Command() noexcept { Command::~Command() noexcept {
} }
void Command::connect() { void Command::connect() {
if (not m_conn) { if (not m_conn) {
RedisConnection conn( RedisConnection conn(
redisAsyncConnect(m_address.c_str(), m_port), (is_socket_connection() ?
redisAsyncConnectUnix(m_address.c_str())
:
redisAsyncConnect(m_address.c_str(), m_port)
),
&redisAsyncDisconnect &redisAsyncDisconnect
); );
if (not conn) { if (not conn) {
@ -155,4 +166,8 @@ namespace redis {
return boost::string_ref(it_inserted->second.data(), it_inserted->second.size()); return boost::string_ref(it_inserted->second.data(), it_inserted->second.size());
} }
#endif #endif
bool Command::is_socket_connection() const {
return not (m_port or m_address.empty());
}
} //namespace redis } //namespace redis

View file

@ -55,6 +55,7 @@ namespace redis {
typedef boost::iterator_range<zscan_iterator> zscan_range; typedef boost::iterator_range<zscan_iterator> zscan_range;
Command ( std::string&& parAddress, uint16_t parPort ); Command ( std::string&& parAddress, uint16_t parPort );
explicit Command ( std::string&& parSocket );
~Command ( void ) noexcept; ~Command ( void ) noexcept;
void connect ( void ); void connect ( void );
@ -80,6 +81,7 @@ namespace redis {
using Sha1Array = std::array<char, 20>; using Sha1Array = std::array<char, 20>;
boost::string_ref add_lua_script_ifn ( const std::string& parScript ); boost::string_ref add_lua_script_ifn ( const std::string& parScript );
bool is_socket_connection ( void ) const;
RedisConnection m_conn; RedisConnection m_conn;
#if defined(WITH_CRYPTOPP) #if defined(WITH_CRYPTOPP)