diff --git a/Redis/include/Poco/Redis/Array.h b/Redis/include/Poco/Redis/Array.h index 67de2bfa0..5b49ece8d 100644 --- a/Redis/include/Poco/Redis/Array.h +++ b/Redis/include/Poco/Redis/Array.h @@ -58,6 +58,11 @@ public: } Array& operator<<(const char* s); + /// Special implementation for const char* + + Array& operator<<(const std::vector& strings); + /// Special implementation for a vector with strings + /// All strings will be added as a BulkString. Array& add(); /// Adds an Null BulkString @@ -76,6 +81,11 @@ public: } Array& add(const char* s); + /// Special implementation for const char* + + Array& add(const std::vector& strings); + /// Special implementation for a vector with strings + /// All strings will be added as a BulkString. Array& addRedisType(RedisType::Ptr value); /// Adds a Redis element. @@ -143,6 +153,11 @@ inline Array& Array::operator<<(const char* s) return add(value); } +inline Array& Array::operator<<(const std::vector& strings) +{ + return add(strings); +} + inline Array& Array::add() { BulkString value; @@ -162,6 +177,15 @@ inline Array& Array::add(const char* s) return add(value); } +inline Array& Array::add(const std::vector& strings) +{ + for(std::vector::const_iterator it = strings.begin(); it != strings.end(); ++it) + { + add(*it); + } + return *this; +} + inline Array& Array::addSimpleString(const std::string& value) { return addRedisType(new Type(value)); diff --git a/Redis/include/Poco/Redis/Command.h b/Redis/include/Poco/Redis/Command.h index a9d0cd773..3ccd05653 100644 --- a/Redis/include/Poco/Redis/Command.h +++ b/Redis/include/Poco/Redis/Command.h @@ -96,6 +96,9 @@ public: static Command hlen(const std::string& hash); /// Returns an HLEN command + static Command hmget(const std::string& hash, const StringVec& fields); + /// Returns an HMGET command + static Command hset(const std::string& hash, const std::string& field, const std::string& value, bool create = true); /// Returns an HSET or HSETNX (when create is false) command diff --git a/Redis/src/Command.cpp b/Redis/src/Command.cpp index e55c49f28..3a420ef47 100644 --- a/Redis/src/Command.cpp +++ b/Redis/src/Command.cpp @@ -47,11 +47,7 @@ Command Command::blpop(const StringVec& lists, Int64 timeout) { Command cmd("BLPOP"); - for(StringVec::const_iterator it = lists.begin(); it != lists.end(); ++it) - { - cmd << *it; - } - cmd << NumberFormatter::format(timeout); + cmd << lists << NumberFormatter::format(timeout); return cmd; } @@ -60,11 +56,7 @@ Command Command::brpop(const StringVec& lists, Int64 timeout) { Command cmd("BRPOP"); - for(StringVec::const_iterator it = lists.begin(); it != lists.end(); ++it) - { - cmd << *it; - } - cmd << NumberFormatter::format(timeout); + cmd << lists << NumberFormatter::format(timeout); return cmd; } @@ -101,10 +93,7 @@ Command Command::del(const StringVec& keys) { Command cmd("DEL"); - for(StringVec::const_iterator it = keys.begin(); it != keys.end(); ++it) - { - cmd << *it; - } + cmd << keys; return cmd; } @@ -131,11 +120,7 @@ Command Command::hdel(const std::string& hash, const StringVec& fields) { Command cmd("HDEL"); - cmd << hash; - for(StringVec::const_iterator it = fields.begin(); it != fields.end(); ++it) - { - cmd << *it; - } + cmd << hash << fields; return cmd; } @@ -194,6 +179,15 @@ Command Command::hlen(const std::string& hash) return cmd; } +Command Command::hmget(const std::string& hash, const StringVec& fields) +{ + Command cmd("HMGET"); + + cmd << hash << fields; + + return cmd; +} + Command Command::hset(const std::string& hash, const std::string& field, const std::string& value, bool create) { Command cmd(create ? "HSET" : "HSETNX"); @@ -266,11 +260,7 @@ Command Command::lpush(const std::string& list, const StringVec& values, bool cr { Command cmd(create ? "LPUSH" : "LPUSHX"); - cmd << list; - for(StringVec::const_iterator it = values.begin(); it != values.end(); ++it) - { - cmd << *it; - } + cmd << list << values; return cmd; } @@ -315,10 +305,7 @@ Command Command::mget(const StringVec& keys) { Command cmd("MGET"); - for(StringVec::const_iterator it = keys.begin(); it != keys.end(); ++it) - { - cmd << *it; - } + cmd << keys; return cmd; } @@ -348,11 +335,7 @@ Command Command::sadd(const std::string& set, const StringVec& values) { Command cmd("SADD"); - cmd << set; - for(StringVec::const_iterator it = values.begin(); it != values.end(); ++it) - { - cmd << *it; - } + cmd << set << values; return cmd; } @@ -379,11 +362,7 @@ Command Command::sdiff(const std::string& set, const StringVec& sets) { Command cmd("SDIFF"); - cmd << set; - for(StringVec::const_iterator it = sets.begin(); it != sets.end(); ++it) - { - cmd << *it; - } + cmd << set << sets; return cmd; } @@ -401,11 +380,7 @@ Command Command::sdiffstore(const std::string& set, const StringVec& sets) { Command cmd("SDIFFSTORE"); - cmd << set; - for(StringVec::const_iterator it = sets.begin(); it != sets.end(); ++it) - { - cmd << *it; - } + cmd << set << sets; return cmd; } @@ -440,11 +415,7 @@ Command Command::sinter(const std::string& set, const StringVec& sets) { Command cmd("SINTER"); - cmd << set; - for(StringVec::const_iterator it = sets.begin(); it != sets.end(); ++it) - { - cmd << *it; - } + cmd << set << sets; return cmd; } @@ -462,11 +433,7 @@ Command Command::sinterstore(const std::string& set, const StringVec& sets) { Command cmd("SINTERSTORE"); - cmd << set; - for(StringVec::const_iterator it = sets.begin(); it != sets.end(); ++it) - { - cmd << *it; - } + cmd << set << sets; return cmd; } @@ -531,11 +498,7 @@ Command Command::srem(const std::string& set, const StringVec& members) { Command cmd("SREM"); - cmd << set; - for(StringVec::const_iterator it = members.begin(); it != members.end(); ++it) - { - cmd << *it; - } + cmd << set << members; return cmd; } @@ -553,11 +516,7 @@ Command Command::sunion(const std::string& set, const StringVec& sets) { Command cmd("SUNION"); - cmd << set; - for(StringVec::const_iterator it = sets.begin(); it != sets.end(); ++it) - { - cmd << *it; - } + cmd << set << sets; return cmd; } @@ -575,11 +534,7 @@ Command Command::sunionstore(const std::string& set, const StringVec& sets) { Command cmd("SUNIONSTORE"); - cmd << set; - for(StringVec::const_iterator it = sets.begin(); it != sets.end(); ++it) - { - cmd << *it; - } + cmd << set << sets; return cmd; } @@ -625,11 +580,7 @@ Command Command::rpush(const std::string& list, const StringVec& values, bool cr { Command cmd(create ? "RPUSH" : "RPUSHX"); - cmd << list; - for(StringVec::const_iterator it = values.begin(); it != values.end(); ++it) - { - cmd << *it; - } + cmd << list << values; return cmd; }