/* Copyright 2016, Michele Santullo
* This file is part of "incredis".
*
* "incredis" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "incredis" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "incredis". If not, see .
*/
#ifndef idD83EEBFC927840C6B9F32D61A1D1E582
#define idD83EEBFC927840C6B9F32D61A1D1E582
#include "reply.hpp"
#include "batch.hpp"
#include "script.hpp"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace redis {
class Command {
public:
Command ( std::string&& parAddress, uint16_t parPort );
explicit Command ( std::string&& parSocket );
~Command ( void ) noexcept;
void connect ( void );
void wait_for_connect ( void );
void disconnect ( void );
void wait_for_disconnect ( void );
bool is_connected ( void ) const;
boost::string_ref connection_error ( void ) const;
Batch make_batch ( void );
Script make_script ( const std::string& parScript );
template
Reply run ( const char* parCommand, Args&&... parArgs );
private:
struct LocalData;
std::unique_ptr m_local_data;
};
template
Reply Command::run (const char* parCommand, Args&&... parArgs) {
auto batch = make_batch();
batch.run(parCommand, std::forward(parArgs)...);
batch.throw_if_failed();
return batch.replies().front();
}
template
struct StructAdapt;
template
inline AS range_as (const boost::iterator_range& parRange) {
assert(not boost::empty(parRange));
AS retval;
const auto success = StructAdapt::decode(parRange, retval);
if (not success)
throw std::runtime_error("Error decoding range");
return retval;
};
} //namespace redis
#endif