/* Copyright 2015, 2016, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" 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.
*
* "dindexer" 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 "dindexer". If not, see .
*/
#ifndef id7D338900114548A890B1EECE0C4D3C4C
#define id7D338900114548A890B1EECE0C4D3C4C
#include "command.hpp"
#include "incredis_batch.hpp"
#include "scan_iterator.hpp"
#include
#include
#include
#include
#include
#include
#include
namespace redis {
class IncRedis {
public:
typedef ScanIterator> scan_iterator;
typedef boost::iterator_range scan_range;
typedef ScanIterator, ScanCommands::HSCAN>> hscan_iterator;
typedef boost::iterator_range hscan_range;
typedef ScanIterator> sscan_iterator;
typedef boost::iterator_range sscan_range;
typedef ScanIterator, ScanCommands::ZSCAN>> zscan_iterator;
typedef boost::iterator_range zscan_range;
typedef boost::optional opt_string;
typedef boost::optional> opt_string_list;
IncRedis ( std::string&& parAddress, uint16_t parPort );
explicit IncRedis ( std::string&& parSocket );
~IncRedis ( void ) noexcept = default;
void connect ( void );
void wait_for_connect ( void );
void disconnect ( void );
void wait_for_disconnect ( void );
bool is_connected ( void ) const { return m_command.is_connected(); }
IncRedisBatch make_batch ( void );
Command& command ( void ) { return m_command; }
const Command& command ( void ) const { return m_command; }
//Scan
scan_range scan ( boost::string_ref parPattern=boost::string_ref() );
hscan_range hscan ( boost::string_ref parKey, boost::string_ref parPattern=boost::string_ref() );
sscan_range sscan ( boost::string_ref parKey, boost::string_ref parPattern=boost::string_ref() );
zscan_range zscan ( boost::string_ref parKey, boost::string_ref parPattern=boost::string_ref() );
//Hash
opt_string hget ( boost::string_ref parKey, boost::string_ref parField );
template
opt_string_list hmget ( boost::string_ref parKey, Args&&... parArgs );
int hincrby ( boost::string_ref parKey, boost::string_ref parField, int parInc );
//Set
opt_string_list srandmember ( boost::string_ref parKey, int parCount );
opt_string srandmember ( boost::string_ref parKey );
//Script
bool script_flush ( void );
private:
static opt_string_list reply_to_string_list ( const Reply& parReply );
Command m_command;
};
template
auto IncRedis::hmget (boost::string_ref parKey, Args&&... parArgs) -> opt_string_list {
static_assert(sizeof...(Args) > 0, "No fields specified");
return reply_to_string_list(m_command.run("HMGET", parKey, std::forward(parArgs)...));
}
} //namespace redis
#endif