overload operator<< and add for vector of strings / hmget

This commit is contained in:
fbraem
2015-11-18 18:47:57 +01:00
parent 52ce9bf469
commit feb9ad31d2
3 changed files with 51 additions and 73 deletions

View File

@@ -58,6 +58,11 @@ public:
}
Array& operator<<(const char* s);
/// Special implementation for const char*
Array& operator<<(const std::vector<std::string>& 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<std::string>& 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<std::string>& 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<std::string>& strings)
{
for(std::vector<std::string>::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<std::string>(value));

View File

@@ -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