From ac26d244a1d4d464e869b931c42712878b85b143 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 25 Apr 2017 00:08:17 +0100 Subject: [PATCH] Add hmset and expire commands --- include/incredis/incredis.hpp | 10 ++++++++++ src/incredis.cpp | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/include/incredis/incredis.hpp b/include/incredis/incredis.hpp index e310c4c..c92a029 100644 --- a/include/incredis/incredis.hpp +++ b/include/incredis/incredis.hpp @@ -70,6 +70,8 @@ namespace redis { opt_string hget ( boost::string_ref parKey, boost::string_ref parField ); template opt_string_list hmget ( boost::string_ref parKey, Args&&... parArgs ); + template + opt_string_list hmset ( boost::string_ref parKey, Args&&... parArgs ); int hincrby ( boost::string_ref parKey, boost::string_ref parField, int parInc ); //Set @@ -86,6 +88,7 @@ namespace redis { //Misc bool flushdb ( void ); RedisInt dbsize ( void ); + bool expire ( boost::string_ref parKey, RedisInt parTTL ); //String opt_string get ( boost::string_ref parKey ); @@ -103,6 +106,13 @@ namespace redis { static_assert(sizeof...(Args) > 0, "No fields specified"); return reply_to_string_list(m_command.run("HMGET", parKey, std::forward(parArgs)...)); } + + template + auto IncRedis::hmset (boost::string_ref parKey, Args&&... parArgs) -> opt_string_list { + static_assert(sizeof...(Args) > 0, "No fields specified"); + static_assert(sizeof...(Args) % 2 == 0, "Uneven number of parameters received"); + return reply_to_string_list(m_command.run("HMSET", parKey, std::forward(parArgs)...)); + } } //namespace redis #endif diff --git a/src/incredis.cpp b/src/incredis.cpp index f69eb9a..62199f6 100644 --- a/src/incredis.cpp +++ b/src/incredis.cpp @@ -141,6 +141,11 @@ namespace redis { return ret; } + bool IncRedis::expire (boost::string_ref parKey, RedisInt parTTL) { + const auto ret = redis::get(m_command.run("EXPIRE", parKey, dhandy::lexical_cast(parTTL))); + return (ret == 1 ? true : false); + } + auto IncRedis::reply_to_string_list (const Reply& parReply) -> opt_string_list { return optional_string_list(parReply); }