From f4c495c5ea44bcc15aabc2a8cf1e3a65de2bce00 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 12 Jul 2016 12:30:17 +0100 Subject: [PATCH] New wrapper methods. --- src/backends/redis/incredis.cpp | 5 ++++ src/backends/redis/incredis.hpp | 4 +++ src/backends/redis/incredis_batch.cpp | 10 ++++++++ src/backends/redis/incredis_batch.hpp | 36 +++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/src/backends/redis/incredis.cpp b/src/backends/redis/incredis.cpp index 3ef978b..2ab7cbb 100644 --- a/src/backends/redis/incredis.cpp +++ b/src/backends/redis/incredis.cpp @@ -115,6 +115,11 @@ namespace redis { return optional_string(m_command.run("SRANDMEMBER", parKey)); } + bool IncRedis::script_flush() { + const auto ret = get(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); } diff --git a/src/backends/redis/incredis.hpp b/src/backends/redis/incredis.hpp index a047e20..e464485 100644 --- a/src/backends/redis/incredis.hpp +++ b/src/backends/redis/incredis.hpp @@ -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 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 diff --git a/src/backends/redis/incredis_batch.cpp b/src/backends/redis/incredis_batch.cpp index f377759..2cae9de 100644 --- a/src/backends/redis/incredis_batch.cpp +++ b/src/backends/redis/incredis_batch.cpp @@ -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(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; diff --git a/src/backends/redis/incredis_batch.hpp b/src/backends/redis/incredis_batch.hpp index 838f68b..b173489 100644 --- a/src/backends/redis/incredis_batch.hpp +++ b/src/backends/redis/incredis_batch.hpp @@ -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& 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 + IncRedisBatch& del ( Args&&... parArgs ); //Hash IncRedisBatch& hget ( boost::string_ref parKey, boost::string_ref parField ); template IncRedisBatch& hmget ( boost::string_ref parKey, Args&&... parArgs ); + template + 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 + IncRedisBatch& sadd ( boost::string_ref parKey, Args&&... parArgs ); + //Script IncRedisBatch& script_flush ( void ); @@ -50,9 +64,31 @@ namespace redis { template IncRedisBatch& IncRedisBatch::hmget (boost::string_ref parKey, Args&&... parArgs) { + static_assert(sizeof...(Args) > 0, "No fields specified"); m_batch.run("HMGET", parKey, std::forward(parArgs)...); return *this; } + + template + 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(parArgs)...); + return *this; + } + + template + IncRedisBatch& IncRedisBatch::sadd (boost::string_ref parKey, Args&&... parArgs) { + static_assert(sizeof...(Args) > 0, "No members specified"); + m_batch.run("SADD", parKey, std::forward(parArgs)...); + return *this; + } + + template + IncRedisBatch& IncRedisBatch::del (Args&&... parArgs) { + static_assert(sizeof...(Args) > 0, "No keys specified"); + m_batch.run("DEL", std::forward(parArgs)...); + return *this; + } } //namespace redis #endif