/* 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 id5B30CDA57F894CD6888093B64F9433DA
#define id5B30CDA57F894CD6888093B64F9433DA
#include "batch.hpp"
#include "helpers/lexical_cast.hpp"
#include "helpers/sequence_bt.hpp"
#include
#include
#include
#include
namespace redis {
class ScriptManager;
class Script {
public:
Script ( void );
Script ( Script&& ) = default;
Script ( boost::string_ref parSha1, ScriptManager& parManager );
~Script ( void ) noexcept = default;
template
void run ( Batch& parBatch, const std::tuple& parKeys, const std::tuple& parValues );
Script& operator= ( Script&& ) = default;
private:
template
void run_with_indices ( Batch& parBatch, const std::tuple& parKeys, const std::tuple& parValues, dinhelp::bt::index_seq, dinhelp::bt::index_seq );
boost::string_ref m_sha1;
ScriptManager* m_manager;
};
template
void Script::run (Batch& parBatch, const std::tuple& parKeys, const std::tuple& parValues) {
this->run_with_indices(
parBatch,
parKeys,
parValues,
::dinhelp::bt::index_range<0, sizeof...(Keys)>(),
::dinhelp::bt::index_range<0, sizeof...(Values)>()
);
}
template
void Script::run_with_indices (Batch& parBatch, const std::tuple& parKeys, const std::tuple& parValues, dinhelp::bt::index_seq, dinhelp::bt::index_seq) {
static_assert(sizeof...(Keys) == sizeof...(KeyIndices), "Wrong index count");
static_assert(sizeof...(Values) == sizeof...(ValueIndices), "Wrong value count");
static_assert(sizeof...(Keys) == std::tuple_size::value, "Wrong key count");
static_assert(sizeof...(Values) == std::tuple_size::value, "Wrong value count");
assert(not m_sha1.empty());
assert(m_manager);
parBatch.run(
"EVALSHA",
m_sha1,
dinhelp::lexical_cast(sizeof...(Keys)),
std::get(parKeys)...,
std::get(parValues)...
);
}
} //namespace redis
#endif