1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-02-19 12:04:54 +00:00

New wrapper methods.

This commit is contained in:
King_DuckZ 2016-07-12 12:30:17 +01:00
parent e0670ff433
commit f4c495c5ea
4 changed files with 55 additions and 0 deletions

View file

@ -115,6 +115,11 @@ namespace redis {
return optional_string(m_command.run("SRANDMEMBER", parKey));
}
bool IncRedis::script_flush() {
const auto ret = get<StatusString>(m_command.run("SCRIPT", "FLUSH"));
return ret.is_ok();
}
auto IncRedis::reply_to_string_list (const Reply& parReply) -> opt_string_list {
return optional_string_list(parReply);
}

View file

@ -75,6 +75,9 @@ namespace redis {
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 );
@ -83,6 +86,7 @@ namespace redis {
template <typename... Args>
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<Args>(parArgs)...));
}
} //namespace redis

View file

@ -52,6 +52,16 @@ namespace redis {
return *this;
}
IncRedisBatch& IncRedisBatch::srandmember (boost::string_ref parKey, int parCount) {
m_batch.run("SRANDMEMBER", parKey, dinhelp::lexical_cast<std::string>(parCount));
return *this;
}
IncRedisBatch& IncRedisBatch::srandmember (boost::string_ref parKey) {
m_batch.run("SRANDMEMBER", parKey);
return *this;
}
IncRedisBatch& IncRedisBatch::script_flush() {
m_batch.run("SCRIPT", "FLUSH");
return *this;

View file

@ -24,23 +24,37 @@
namespace redis {
class IncRedisBatch {
public:
IncRedisBatch ( void ) = delete;
IncRedisBatch ( IncRedisBatch&& ) = default;
IncRedisBatch ( const Batch& ) = delete;
IncRedisBatch ( Batch&& parBatch );
void reset ( void );
void throw_if_failed ( void );
const std::vector<Reply>& replies ( void ) { return m_batch.replies(); }
Batch& batch ( void ) { return m_batch; }
const Batch& batch ( void ) const { return m_batch; }
//Misc
IncRedisBatch& select ( int parIndex );
IncRedisBatch& client_setname ( boost::string_ref parName );
template <typename... Args>
IncRedisBatch& del ( Args&&... parArgs );
//Hash
IncRedisBatch& hget ( boost::string_ref parKey, boost::string_ref parField );
template <typename... Args>
IncRedisBatch& hmget ( boost::string_ref parKey, Args&&... parArgs );
template <typename... Args>
IncRedisBatch& hmset ( boost::string_ref parKey, Args&&... parArgs );
IncRedisBatch& hincrby ( boost::string_ref parKey, boost::string_ref parField, int parInc );
//Set
IncRedisBatch& srandmember ( boost::string_ref parKey, int parCount );
IncRedisBatch& srandmember ( boost::string_ref parKey );
template <typename... Args>
IncRedisBatch& sadd ( boost::string_ref parKey, Args&&... parArgs );
//Script
IncRedisBatch& script_flush ( void );
@ -50,9 +64,31 @@ namespace redis {
template <typename... Args>
IncRedisBatch& IncRedisBatch::hmget (boost::string_ref parKey, Args&&... parArgs) {
static_assert(sizeof...(Args) > 0, "No fields specified");
m_batch.run("HMGET", parKey, std::forward<Args>(parArgs)...);
return *this;
}
template <typename... Args>
IncRedisBatch& IncRedisBatch::hmset (boost::string_ref parKey, Args&&... parArgs) {
static_assert(sizeof...(Args) % 2 == 0, "Uneven number of parameters received");
m_batch.run("HMSET", parKey, std::forward<Args>(parArgs)...);
return *this;
}
template <typename... Args>
IncRedisBatch& IncRedisBatch::sadd (boost::string_ref parKey, Args&&... parArgs) {
static_assert(sizeof...(Args) > 0, "No members specified");
m_batch.run("SADD", parKey, std::forward<Args>(parArgs)...);
return *this;
}
template <typename... Args>
IncRedisBatch& IncRedisBatch::del (Args&&... parArgs) {
static_assert(sizeof...(Args) > 0, "No keys specified");
m_batch.run("DEL", std::forward<Args>(parArgs)...);
return *this;
}
} //namespace redis
#endif