mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-20 12:14:55 +00:00
Add constructor for opening connection to socket.
This commit is contained in:
parent
c61619eb38
commit
29e2375e3b
2 changed files with 18 additions and 1 deletions
|
@ -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 {
|
||||
}
|
||||
|
||||
void Command::connect() {
|
||||
if (not m_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
|
||||
);
|
||||
if (not conn) {
|
||||
|
@ -155,4 +166,8 @@ namespace redis {
|
|||
return boost::string_ref(it_inserted->second.data(), it_inserted->second.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Command::is_socket_connection() const {
|
||||
return not (m_port or m_address.empty());
|
||||
}
|
||||
} //namespace redis
|
||||
|
|
|
@ -55,6 +55,7 @@ namespace redis {
|
|||
typedef boost::iterator_range<zscan_iterator> zscan_range;
|
||||
|
||||
Command ( std::string&& parAddress, uint16_t parPort );
|
||||
explicit Command ( std::string&& parSocket );
|
||||
~Command ( void ) noexcept;
|
||||
|
||||
void connect ( void );
|
||||
|
@ -80,6 +81,7 @@ namespace redis {
|
|||
using Sha1Array = std::array<char, 20>;
|
||||
|
||||
boost::string_ref add_lua_script_ifn ( const std::string& parScript );
|
||||
bool is_socket_connection ( void ) const;
|
||||
|
||||
RedisConnection m_conn;
|
||||
#if defined(WITH_CRYPTOPP)
|
||||
|
|
Loading…
Add table
Reference in a new issue