style and documentation fixes

This commit is contained in:
Guenter Obiltschnig 2016-09-04 14:30:26 +02:00
parent fd9ca0a9b6
commit 64781d15f1
27 changed files with 791 additions and 487 deletions

View File

@ -9,69 +9,74 @@
//
// Definition of the Array class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Redis_Array_INCLUDED
#define Redis_Array_INCLUDED
#include <vector>
#include <sstream>
#include "Poco/Redis/Redis.h"
#include "Poco/Redis/Type.h"
#include "Poco/Redis/Exception.h"
#include <vector>
#include <sstream>
namespace Poco {
namespace Redis {
class Redis_API Array
/// Represents a Redis Array. An Array can contain Integers, Strings,
/// Bulk Strings, Errors and other arrays. It can also contain a Null
/// Bulk Strings, Errors and other Arrays. It can also contain a Null
/// value.
{
public:
typedef std::vector<RedisType::Ptr>::const_iterator const_iterator;
Array();
/// Default constructor. As long as there are no elements added,
/// Creates an Array. As long as there are no elements added,
/// the array will contain a Null value.
Array(const Array& copy);
/// Copy constructor.
/// Creates an Array by copying another one.
virtual ~Array();
/// Destructor.
/// Destroys the Array.
template<typename T>
Array& operator<<(const T& arg)
/// Adds the argument to the array.
///
/// Note: a std::string will be added as a BulkString because this
/// is commonly used for representing strings in Redis. If you
/// really need a simple string, use addSimpleString.
/// really need a simple string, use addSimpleString().
{
return add(arg);
}
Array& operator<<(const char* s);
/// Special implementation for const char*
/// Special implementation for const char*.
///
/// Note: the specialization creates a BulkString. If you need
/// a simple string, call addSimpleString.
/// a simple string, call addSimpleString().
Array& operator<<(const std::vector<std::string>& strings);
/// Special implementation for a vector with strings
/// Special implementation for a vector with strings.
/// All strings will be added as a BulkString.
Array& add();
/// Adds an Null BulkString
/// Adds an Null BulkString.
template<typename T>
Array& add(const T& arg)
/// Adds an element to the array.
///
/// Note: the specialization for std::string will add a BulkString!
/// If you really need a simple string, call addSimpleString.
{
@ -80,38 +85,41 @@ public:
}
Array& add(const char* s);
/// Special implementation for const char*
/// Special implementation for const char*.
///
/// Note: the specialization creates a BulkString. If you need
/// a simple string, call addSimpleString.
Array& add(const std::vector<std::string>& strings);
/// Special implementation for a vector with 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.
Array& addSimpleString(const std::string& value);
/// Adds a simple string (can't contain newline characters!)
/// Adds a simple string (can't contain newline characters!).
const_iterator begin() const;
/// Returns an iterator to the start of the array. Note:
/// this can throw a NullValueException when this is a Null array.
/// Returns an iterator to the start of the array.
///
/// Note: this can throw a NullValueException when this is a Null array.
void clear();
/// Removes all elements from the array.
const_iterator end() const;
/// Returns an iterator to the end of the array. Note:
/// this can throw a NullValueException when this is a Null array.
/// Returns an iterator to the end of the array.
///
/// Note: this can throw a NullValueException when this is a Null array.
template<typename T>
T get(size_t pos) const
/// Returns the element on the given position and tries to convert
/// to the template type. A BadCastException will be thrown when the
/// the conversion fails. An InvalidArgumentException will be thrown
/// to the template type. A Poco::BadCastException will be thrown when the
/// the conversion fails. An Poco::InvalidArgumentException will be thrown
/// when the index is out of range. When the array is a Null array
/// a NullValueException is thrown.
/// a Poco::NullValueException is thrown.
{
if ( _elements.isNull() ) throw NullValueException();
@ -127,8 +135,8 @@ public:
}
int getType(size_t pos) const;
/// Returns the type of the element. This can throw a NullValueException
/// when this array is a Null array. An InvalidArgumentException will
/// Returns the type of the element. This can throw a Poco::NullValueException
/// when this array is a Null array. An Poco::InvalidArgumentException will
/// be thrown when the index is out of range.
bool isNull() const;
@ -143,34 +151,43 @@ public:
/// Redis Protocol specification.
size_t size() const;
/// Returns the size of the array. Note:
/// this can throw a NullValueException when this is a Null array.
/// Returns the size of the array.
///
/// Note: this can throw a NullValueException when this is a Null array.
private:
Nullable<std::vector<RedisType::Ptr> > _elements;
void checkNull();
/// Checks for null array and sets a new vector if true.
Nullable<std::vector<RedisType::Ptr> > _elements;
};
//
// inlines
//
inline Array& Array::operator<<(const char* s)
{
BulkString value(s);
return add(value);
}
inline Array& Array::operator<<(const std::vector<std::string>& strings)
{
return add(strings);
}
inline Array& Array::add()
{
BulkString value;
return add(value);
}
template<>
inline Array& Array::add(const std::string& arg)
{
@ -178,12 +195,14 @@ inline Array& Array::add(const std::string& arg)
return add(value);
}
inline Array& Array::add(const char* s)
{
BulkString value(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)
@ -193,22 +212,26 @@ inline Array& Array::add(const std::vector<std::string>& strings)
return *this;
}
inline Array& Array::addSimpleString(const std::string& value)
{
return addRedisType(new Type<std::string>(value));
}
inline Array::const_iterator Array::begin() const
{
return _elements.value().begin();
}
inline void Array::checkNull()
{
std::vector<RedisType::Ptr> v;
if ( _elements.isNull() ) _elements.assign(v);
}
inline void Array::clear()
{
if ( !_elements.isNull() )
@ -217,16 +240,19 @@ inline void Array::clear()
}
}
inline Array::const_iterator Array::end() const
{
return _elements.value().end();
}
inline bool Array::isNull() const
{
return _elements.isNull();
}
inline void Array::makeNull()
{
if ( !_elements.isNull() ) _elements.value().clear();
@ -234,6 +260,7 @@ inline void Array::makeNull()
_elements.clear();
}
inline size_t Array::size() const
{
return _elements.value().size();
@ -291,6 +318,7 @@ struct RedisTypeTraits<Array>
};
}}
} } // namespace Poco::Redis
#endif // Redis_Array_INCLUDED

View File

@ -9,7 +9,7 @@
//
// Definition of the AsyncReader class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
@ -25,6 +25,7 @@
#include "Poco/Redis/RedisEventArgs.h"
#include "Poco/Activity.h"
namespace Poco {
namespace Redis {
@ -37,17 +38,17 @@ class Redis_API AsyncReader
/// reading all replies.
{
public:
BasicEvent<RedisEventArgs> redisResponse;
/// Event that is called when a message is received
/// Event that is fired when a message is received.
BasicEvent<RedisEventArgs> redisException;
/// Event that is called when an error occurred.
/// Event that is fired when an error occurred.
AsyncReader(Client& client);
/// Constructor.
/// Creates the AsyncReader using the given Client.
virtual ~AsyncReader();
/// Destructor
/// Destroys the AsyncReader.
bool isStopped();
/// Returns true if the activity is not running, false when it is.
@ -59,11 +60,9 @@ public:
/// Stops the read activity.
protected:
void runActivity();
private:
AsyncReader(const AsyncReader&);
AsyncReader& operator = (const AsyncReader&);
@ -72,16 +71,23 @@ private:
};
//
// inlines
//
inline bool AsyncReader::isStopped()
{
return _activity.isStopped();
}
inline void AsyncReader::start()
{
_activity.start();
}
inline void AsyncReader::stop()
{
_activity.stop();
@ -90,4 +96,5 @@ inline void AsyncReader::stop()
} } // namespace Poco::Redis
#endif //Redis_AsyncReader_INCLUDED

View File

@ -9,7 +9,7 @@
//
// Definition of the Client class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
@ -19,13 +19,14 @@
#ifndef Redis_Client_INCLUDED
#define Redis_Client_INCLUDED
#include "Poco/Net/SocketAddress.h"
#include "Poco/Timespan.h"
#include "Poco/Redis/Redis.h"
#include "Poco/Redis/Array.h"
#include "Poco/Redis/Error.h"
#include "Poco/Redis/RedisStream.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Timespan.h"
namespace Poco {
namespace Redis {
@ -41,43 +42,42 @@ class Redis_API Client
/// implemented as a typedef for Poco::Nullable<std::string>. This is
/// because a bulk string can represent a Null value.
///
/// BulkString bs = client.execute<BulkString>(...);
/// if ( bs.isNull() )
/// {
/// // We have a Null value
/// }
/// else
/// {
/// // We have a string value
/// }
/// BulkString bs = client.execute<BulkString>(...);
/// if ( bs.isNull() )
/// {
/// // We have a Null value
/// }
/// else
/// {
/// // We have a string value
/// }
///
/// To create Redis commands, the factory methods of the Command class can
/// be used or the Array class can be used directly.
///
/// Command llen = Command::llen("list");
/// Command llen = Command::llen("list");
///
/// is the same as
/// is the same as:
///
/// Array command;
/// command.add("LLEN").add("list");
/// Array command;
/// command.add("LLEN").add("list");
///
/// or
/// or:
///
/// Array command;
/// command << "LLEN" << "list";
/// Array command;
/// command << "LLEN" << "list";
///
/// or even
/// or even:
///
/// Command command("LLEN");
/// command << "list";
/// Command command("LLEN");
/// command << "list";
{
public:
typedef SharedPtr<Client> Ptr;
Client();
/// Default constructor. Use this when you want to
/// connect later on.
/// Creates an unconnected Client.
/// Use this when you want to connect later on.
Client(const std::string& hostAndPort);
/// Constructor which connects to the given Redis host/port.
@ -90,7 +90,7 @@ public:
/// Constructor which connects to the given Redis host/port.
virtual ~Client();
/// Destructor.
/// Destroys the Client.
Net::SocketAddress address() const;
/// Returns the address of the Redis connection.
@ -125,9 +125,9 @@ public:
///
/// A specialization exists for type void, which doesn't read
/// the reply. If the server sends a reply, it is your
/// responsibility to read it ... (Use this for pipelining)
/// responsibility to read it. Use this for pipelining.
///
/// A BadCastException will be thrown when the reply couldn't be
/// A Poco::BadCastException will be thrown when the reply couldn't be
/// converted. Supported types are Int64, std::string, BulkString,
/// Array and void. When the reply is an Error, it will throw
/// a RedisException.
@ -179,13 +179,9 @@ public:
/// Sets a receive timeout.
private:
Client(const Client&);
Client& operator = (const Client&);
Net::SocketAddress _address;
Net::StreamSocket _socket;
void connect();
/// Connects to the Redis server
@ -198,28 +194,38 @@ private:
/// call readReply as many times as you called writeCommand, even when
/// an error occurred on a command.
Net::SocketAddress _address;
Net::StreamSocket _socket;
RedisInputStream* _input;
RedisOutputStream* _output;
};
//
// inlines
//
inline Net::SocketAddress Client::address() const
{
return _address;
}
template<> inline
void Client::execute<void>(const Array& command)
{
writeCommand(command, false);
}
inline void Client::flush()
{
poco_assert(_output);
_output->flush();
}
inline void Client::setReceiveTimeout(const Timespan& timeout)
{
_socket.setReceiveTimeout(timeout);
@ -229,4 +235,4 @@ inline void Client::setReceiveTimeout(const Timespan& timeout)
} } // namespace Poco::Redis
#endif //Redis_Client_INCLUDED
#endif // Redis_Client_INCLUDED

View File

@ -9,248 +9,255 @@
//
// Definition of the Command class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Redis_Command_INCLUDED
#define Redis_Command_INCLUDED
#include "Poco/Redis/Redis.h"
#include "Poco/Redis/Array.h"
#include <vector>
#include <map>
namespace Poco {
namespace Redis {
class Redis_API Command : public Array
class Redis_API Command: public Array
/// Helper class for creating commands. This class contains
/// factory methods for commonly used Redis commands.
///
/// There are two ways of building commands:
/// 1. Use this class and the factory methods
/// 2. Use the Array or Command class and build the command using the add
/// method or << operator.
///
/// 1. Use this class and the factory methods
/// 2. Use the Array or Command class and build the command using the add
/// method or << operator.
///
/// For example:
///
/// Command cmd = Command::set("mykey", "Hello");
/// Command cmd = Command::set("mykey", "Hello");
///
/// is the same as:
///
/// Array cmd;
/// cmd << "SET" << "mykey" << "Hello";
/// Array cmd;
/// cmd << "SET" << "mykey" << "Hello";
///
{
public:
typedef std::vector<std::string> StringVec;
Command(const std::string& command);
/// Constructor
/// Creates a command.
Command(const Command& copy);
/// Copy constructor
/// Creates a command by copying another one.
virtual ~Command();
/// Destructor
/// Destroys the command.
static Command append(const std::string& key, const std::string& value);
/// Returns an APPEND command
/// Creates and returns an APPEND command.
static Command blpop(const StringVec& lists, Int64 timeout = 0);
/// Returns a BLPOP command
/// Creates and returns a BLPOP command.
static Command brpop(const StringVec& lists, Int64 timeout = 0);
/// Returns a BRPOP command
/// Creates and returns a BRPOP command.
static Command brpoplpush(const std::string& sourceList, const std::string& destinationList, Int64 timeout = 0);
/// Returns a BRPOPLPUSH command
/// Creates and returns a BRPOPLPUSH command.
static Command decr(const std::string& key, Int64 by = 0);
/// Returns an DECR or DECRBY command. Calls DECR when by is omitted or zero.
/// Creates and returns an DECR or DECRBY command. Calls DECR when by is omitted or zero.
static Command del(const std::string& key);
/// Returns an DEL command
/// Creates and returns an DEL command.
static Command del(const StringVec& keys);
/// Returns an DEL command
/// Creates and returns an DEL command.
static Command get(const std::string& key);
/// Returns an GET command
/// Creates and returns an GET command.
static Command hdel(const std::string& hash, const std::string& field);
/// Returns an HDEL command
/// Creates and returns an HDEL command.
static Command hdel(const std::string& hash, const StringVec& fields);
/// Returns an HDEL command
/// Creates and returns an HDEL command.
static Command hexists(const std::string& hash, const std::string& field);
/// Returns an HEXISTS command
/// Creates and returns an HEXISTS command.
static Command hget(const std::string& hash, const std::string& field);
/// Returns an HGET command
/// Creates and returns an HGET command.
static Command hgetall(const std::string& hash);
/// Returns an HGETALL command
/// Creates and returns an HGETALL command.
static Command hincrby(const std::string& hash, const std::string& field, Int64 by = 1);
/// Returns an HINCRBY command
/// Creates and returns an HINCRBY command.
static Command hkeys(const std::string& hash);
/// Returns an HKEYS command
/// Creates and returns an HKEYS command.
static Command hlen(const std::string& hash);
/// Returns an HLEN command
/// Creates and returns an HLEN command.
static Command hmget(const std::string& hash, const StringVec& fields);
/// Returns an HMGET command
/// Creates and returns an HMGET command.
static Command hmset(const std::string& hash, std::map<std::string, std::string>& fields);
/// Returns a HMSET command
/// Creates and returns a HMSET 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
/// Creates and returns an HSET or HSETNX (when create is false) command.
static Command hset(const std::string& hash, const std::string& field, Int64 value, bool create = true);
/// Returns an HSET or HSETNX (when create is false) command
/// Creates and returns an HSET or HSETNX (when create is false) command.
static Command hstrlen(const std::string& hash, const std::string& field);
/// Returns an HSTRLEN command (Available for Redis 3.2)
/// Creates and returns an HSTRLEN command (Available for Redis 3.2).
static Command hvals(const std::string& hash);
/// Returns an HVALS command
/// Creates and returns an HVALS command.
static Command incr(const std::string& key, Int64 by = 0);
/// Returns an INCR or INCRBY command. Calls INCR when by is omitted or zero.
/// Creates and returns an INCR or INCRBY command. Calls INCR when by is omitted or zero.
static Command lindex(const std::string& list, Int64 index = 0);
/// Returns a LINDEX command
/// Creates and returns a LINDEX command.
static Command linsert(const std::string& list, bool before, const std::string& reference, const std::string& value);
/// Returns a LINSERT command
/// Creates and returns a LINSERT command.
static Command llen(const std::string& list);
/// Returns a LLEN command
/// Creates and returns a LLEN command.
static Command lpop(const std::string& list);
/// Returns a LPOP command
/// Creates and returns a LPOP command.
static Command lpush(const std::string& list, const std::string& value, bool create = true);
/// Returns a LPUSH or LPUSHX (when create is false) command
/// Creates and returns a LPUSH or LPUSHX (when create is false) command.
static Command lpush(const std::string& list, const StringVec& value, bool create = true);
/// Returns a LPUSH or LPUSHX (when create is false) command
/// Creates and returns a LPUSH or LPUSHX (when create is false) command.
static Command lrange(const std::string& list, Int64 start = 0, Int64 stop = -1);
/// Returns a LRANGE command. When start and stop is omitted an LRANGE
/// Creates and returns a LRANGE command. When start and stop is omitted an LRANGE
/// command will returned that returns all items of the list.
static Command lrem(const std::string& list, Int64 count, const std::string& value);
/// Returns a LREM command
/// Creates and returns a LREM command.
static Command lset(const std::string& list, Int64 index, const std::string& value);
/// Returns a LSET command
/// Creates and returns a LSET command.
static Command ltrim(const std::string& list, Int64 start = 0, Int64 stop = -1);
/// Returns a LTRIM command
/// Creates and returns a LTRIM command.
static Command mget(const StringVec& keys);
/// Returns a MGET command
/// Creates and returns a MGET command.
static Command mset(const std::map<std::string, std::string>& keyvalues, bool create = true);
/// Returns a MSET or MSETNX (when create is false) command
/// Creates and returns a MSET or MSETNX (when create is false) command.
static Command sadd(const std::string& set, const std::string& value);
/// Returns a SADD command
/// Creates and returns a SADD command.
static Command sadd(const std::string& set, const StringVec& values);
/// Returns a SADD command
/// Creates and returns a SADD command.
static Command scard(const std::string& set);
/// Returns a SCARD command
/// Creates and returns a SCARD command.
static Command sdiff(const std::string& set1, const std::string& set2);
/// Returns a SDIFF command
/// Creates and returns a SDIFF command.Creates and returns
static Command sdiff(const std::string& set, const StringVec& sets);
/// Returns a SDIFF command
/// Creates and returns a SDIFF command.
static Command sdiffstore(const std::string& set, const std::string& set1, const std::string& set2);
/// Returns a SDIFFSTORE command
/// Creates and returns a SDIFFSTORE command.
static Command sdiffstore(const std::string& set, const StringVec& sets);
/// Returns a SDIFFSTORE command
/// Creates and returns a SDIFFSTORE command.
static Command set(const std::string& key, const std::string& value, bool overwrite = true, const Poco::Timespan& expireTime = 0, bool create = true);
/// Returns a SET command to set the key with a value
/// Creates and returns a SET command to set the key with a value.
static Command set(const std::string& key, Int64 value, bool overwrite = true, const Poco::Timespan& expireTime = 0, bool create = true);
/// Returns a SET command to set the key with a value
/// Creates and returns a SET command to set the key with a value.
static Command sinter(const std::string& set1, const std::string& set2);
/// Returns a SINTER command
/// Creates and returns a SINTER command.
static Command sinter(const std::string& set, const StringVec& sets);
/// Returns a SINTER command
/// Creates and returns a SINTER command.
static Command sinterstore(const std::string& set, const std::string& set1, const std::string& set2);
/// Returns a SINTERSTORE command
/// Creates and returns a SINTERSTORE command.
static Command sinterstore(const std::string& set, const StringVec& sets);
/// Returns a SINTERSTORE command
/// Creates and returns a SINTERSTORE command.
static Command sismember(const std::string& set, const std::string& member);
/// Returns a SISMEMBER command
/// Creates and returns a SISMEMBER command.
static Command smembers(const std::string& set);
/// Returns a SMEMBERS command
/// Creates and returns a SMEMBERS command.
static Command smove(const std::string& source, const std::string& destination, const std::string& member);
/// Returns a SMOVE command
/// Creates and returns a SMOVE command.
static Command spop(const std::string& set, Int64 count = 0);
/// Returns a SPOP command
/// Creates and returns a SPOP command.
static Command srandmember(const std::string& set, Int64 count = 0);
/// Returns a SRANDMEMBER command
/// Creates and returns a SRANDMEMBER command.
static Command srem(const std::string& set, const std::string& member);
/// Returns a SREM command
/// Creates and returns a SREM command.
static Command srem(const std::string& set, const StringVec& members);
/// Returns a SREM command
/// Creates and returns a SREM command.
static Command sunion(const std::string& set1, const std::string& set2);
/// Returns a SUNION command
/// Creates and returns a SUNION command.
static Command sunion(const std::string& set, const StringVec& sets);
/// Returns a SUNION command
/// Creates and returns a SUNION command.
static Command sunionstore(const std::string& set, const std::string& set1, const std::string& set2);
/// Returns a SUNIONSTORE command
/// Creates and returns a SUNIONSTORE command.
static Command sunionstore(const std::string& set, const StringVec& sets);
/// Returns a SUNIONSTORE command
/// Creates and returns a SUNIONSTORE command.
static Command rename(const std::string& key, const std::string& newName, bool overwrite = true);
/// Returns a RENAME or RENAMENX when overwrite is false
/// Creates and returns a RENAME or RENAMENX when overwrite is false.
static Command rpop(const std::string& list);
/// Returns a RPOP command
/// Creates and returns a RPOP command.
static Command rpoplpush(const std::string& sourceList, const std::string& destinationList);
/// Returns a RPOPLPUSH command
/// Creates and returns a RPOPLPUSH command.
static Command rpush(const std::string& list, const std::string& value, bool create = true);
/// Returns a RPUSH or RPUSHX (when create is false) command
/// Creates and returns a RPUSH or RPUSHX (when create is false) command.
static Command rpush(const std::string& list, const StringVec& value, bool create = true);
/// Returns a RPUSH or RPUSHX (when create is false) command
/// Creates and returns a RPUSH or RPUSHX (when create is false) command.
};
}} // namespace Poco::Redis
} } // namespace Poco::Redis
#endif // Redis_Command_INCLUDED

View File

@ -9,55 +9,65 @@
//
// Definition of the Error class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Redis_Error_INCLUDED
#define Redis_Error_INCLUDED
#include "Poco/Redis/Type.h"
namespace Poco {
namespace Redis {
class Redis_API Error
/// Represent a Redis error
/// Represent a Redis error.
{
public:
Error();
/// Constructor
/// Creates an empty Error.
Error(const std::string& message);
/// Constructor
/// Creates an Error with the given message.
virtual ~Error();
/// Destructor
/// Destroys the Error.
std::string getMessage() const;
/// Returns the error message
const std::string& getMessage() const;
/// Returns the error message.
void setMessage(const std::string& message);
/// Sets the error message
/// Sets the error message.
private:
std::string _message;
};
inline std::string Error::getMessage() const
//
// inlines
//
inline const std::string& Error::getMessage() const
{
return _message;
}
inline void Error::setMessage(const std::string& message)
{
_message = message;
}
template<>
struct RedisTypeTraits<Error>
{
@ -76,6 +86,8 @@ struct RedisTypeTraits<Error>
}
};
}} // Namespace Poco::Redis
#endif // Redis_Error_INCLUDED
} } // namespace Poco::Redis
#endif // Redis_Error_INCLUDED

View File

@ -9,24 +9,30 @@
//
// Definition of the Exception class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Redis_Exception_INCLUDED
#define Redis_Exception_INCLUDED
#include "Poco/Redis/Redis.h"
#include <typeinfo>
#include "Poco/Exception.h"
#include <typeinfo>
namespace Poco {
namespace Redis {
POCO_DECLARE_EXCEPTION(Redis_API, RedisException, Exception)
}}
} } // namespace Poco::Redis
#endif // Redis_Exception_INCLUDED

View File

@ -9,7 +9,7 @@
//
// Definition of the PoolableConnectionFactory class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
@ -22,6 +22,7 @@
#include "Poco/Redis/Client.h"
#include "Poco/ObjectPool.h"
#include "Poco/Version.h"
namespace Poco {
@ -33,13 +34,13 @@ class PoolableObjectFactory<Redis::Client, Redis::Client::Ptr>
/// are created with the given address.
{
public:
PoolableObjectFactory(Net::SocketAddress& address)
: _address(address)
PoolableObjectFactory(Net::SocketAddress& address):
_address(address)
{
}
PoolableObjectFactory(const std::string& address)
: _address(address)
PoolableObjectFactory(const std::string& address):
_address(address)
{
}
@ -79,7 +80,11 @@ class PooledConnection
public:
PooledConnection(ObjectPool<Client, Client::Ptr>& pool, long timeoutMilliseconds = 0) : _pool(pool)
{
#if POCO_VERSION >= 0x01080000
_client = _pool.borrowObject(timeoutMilliseconds);
#else
_client = _pool.borrowObject();
#endif
}
virtual ~PooledConnection()
@ -94,7 +99,7 @@ public:
}
}
operator Client::Ptr ()
operator Client::Ptr()
{
return _client;
}
@ -105,7 +110,7 @@ private:
};
} // namespace Redis
} // namespace Poco
} } // namespace Poco::Redis
#endif // Redis_PoolableConnectionFactory_INCLUDED

View File

@ -11,7 +11,7 @@
// This file must be the first file included by every other Redis
// header file.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
@ -33,8 +33,6 @@
// Redis_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(_WIN32) && defined(POCO_DLL)
#if defined(Redis_EXPORTS)
#define Redis_API __declspec(dllexport)

View File

@ -9,47 +9,53 @@
//
// Definition of the RedisEventArgs class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Redis_RedisEventArgs_INCLUDED
#define Redis_RedisEventArgs_INCLUDED
#include "Poco/Redis/Type.h"
namespace Poco {
namespace Redis {
class Redis_API RedisEventArgs
/// Event arguments for AsyncReader events.
{
public:
RedisEventArgs(RedisType::Ptr message);
/// Constructor
/// Creates the RedisEventArgs from the given message.
RedisEventArgs(Exception* e);
/// Constructor
/// Creates the RedisEventArgs from the given Redis Exception.
~RedisEventArgs();
/// Destructor
/// Destroys the RedisEventArgs.
RedisType::Ptr message() const;
/// Returns the message retrieved from the Redis server.
/// This can be a NULL pointer when this event is about an exception.
const Exception* exception() const;
/// Returns the exception if any, otherwise it returns null pointer
/// Returns the exception if any, otherwise it returns null pointer.
void stop();
/// When called, the AsyncReader will stop.
///
/// Note: The AsyncReader will always stop when this is an exception
/// event. Use this for example for pub/sub when there are no
/// subcribers anymore ...
/// subcribers anymore.
bool isStopped() const;
/// Returns true when the AsyncReader will stop
/// Returns true when the AsyncReader will stop.
private:
RedisType::Ptr _message;
@ -59,27 +65,37 @@ private:
bool _stop;
};
//
// inlines
//
inline RedisType::Ptr RedisEventArgs::message() const
{
return _message;
}
inline const Exception* RedisEventArgs::exception() const
{
return _exception;
}
inline bool RedisEventArgs::isStopped() const
{
return _stop;
}
inline void RedisEventArgs::stop()
{
_stop = true;
}
}} // namespace Poco::Redis
} } // namespace Poco::Redis
#endif // Redis_RedisEventArgs_INCLUDED

View File

@ -9,27 +9,30 @@
//
// Definition of the RedisStream class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Redis_RedisStream_INCLUDED
#define Redis_RedisStream_INCLUDED
#include "Poco/Redis/Redis.h"
#include "Poco/BufferedStreamBuf.h"
#include "Poco/Net/StreamSocket.h"
#include <istream>
#include <ostream>
namespace Poco {
namespace Redis {
class RedisStreamBuf : public BufferedStreamBuf
/// BufferedStreamBuf for Redis
class RedisStreamBuf: public BufferedStreamBuf
/// BufferedStreamBuf for Redis.
{
public:
RedisStreamBuf(Net::StreamSocket& redis);
@ -43,11 +46,9 @@ public:
protected:
int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length);
private:
enum
{
STREAM_BUFFER_SIZE = 1024
@ -56,6 +57,7 @@ private:
Net::StreamSocket& _redis;
};
class RedisIOS: public virtual std::ios
{
public:
@ -103,11 +105,12 @@ public:
/// Destroys the RedisInputStream.
std::string getline();
/// Redis uses /r/n as delimiter. This getline version removes
/// the /r from the result.
/// Redis uses \r\n as delimiter. This getline version removes
/// the \r from the result.
};
}} // Poco::Redis
} } // namespace Poco::Redis
#endif // Redis_RedisStream_INCLUDED
#endif // Redis_RedisStream_INCLUDED

View File

@ -9,24 +9,26 @@
//
// Definition of the Type class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2016, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Redis_Type_INCLUDED
#define Redis_Type_INCLUDED
#include "Poco/LineEndingConverter.h"
#include "Poco/NumberFormatter.h"
#include "Poco/NumberParser.h"
#include "Poco/SharedPtr.h"
#include "Poco/Nullable.h"
#include "Poco/Redis/Redis.h"
#include "Poco/Redis/RedisStream.h"
namespace Poco {
namespace Redis {
@ -36,22 +38,22 @@ class Redis_API RedisType
/// element with different types in Array.
{
public:
enum Types {
REDIS_INTEGER, // Redis Integer
REDIS_SIMPLE_STRING, // Redis Simple String
REDIS_BULK_STRING, // Redis Bulkstring
REDIS_ARRAY, // Redis Array
REDIS_ERROR // Redis Error
enum Types
{
REDIS_INTEGER, /// Redis Integer
REDIS_SIMPLE_STRING, /// Redis Simple String
REDIS_BULK_STRING, /// Redis Bulkstring
REDIS_ARRAY, /// Redis Array
REDIS_ERROR /// Redis Error
};
typedef SharedPtr<RedisType> Ptr;
RedisType();
/// Constructor
/// Creates the RedisType.
virtual ~RedisType();
/// Destructor
/// Destroys the RedisType.
bool isArray() const;
/// Returns true when the value is a Redis array.
@ -63,7 +65,7 @@ public:
/// Returns true when the value is a Redis error.
bool isInteger() const;
/// Returns true when the value is a Redis integer (64 bit integer)
/// Returns true when the value is a Redis integer (64 bit integer).
bool isSimpleString() const;
/// Returns true when the value is a simple string.
@ -78,42 +80,51 @@ public:
/// Converts the value to a RESP (REdis Serialization Protocol) string.
static RedisType::Ptr createRedisType(char marker);
/// Create a Redis type based on the marker :
/// + : a simple string (std::string)
/// - : an error (Error)
/// $ : a bulk string (BulkString)
/// * : an array (Array)
/// : : a signed 64 bit integer (Int64)
private:
/// Create a Redis type based on the marker:
///
/// - '+': a simple string (std::string)
/// - '-': an error (Error)
/// - '$': a bulk string (BulkString)
/// - '*': an array (Array)
/// - ':': a signed 64 bit integer (Int64)
};
//
// inlines
//
inline bool RedisType::isArray() const
{
return type() == REDIS_ARRAY;
}
inline bool RedisType::isBulkString() const
{
return type() == REDIS_BULK_STRING;
}
inline bool RedisType::isError() const
{
return type() == REDIS_ERROR;
}
inline bool RedisType::isInteger() const
{
return type() == REDIS_INTEGER;
}
inline bool RedisType::isSimpleString() const
{
return type() == REDIS_SIMPLE_STRING;
}
template<typename T>
struct RedisTypeTraits
{
@ -123,7 +134,10 @@ struct RedisTypeTraits
template<>
struct RedisTypeTraits<Int64>
{
enum { TypeId = RedisType::REDIS_INTEGER };
enum
{
TypeId = RedisType::REDIS_INTEGER
};
static const char marker = ':';
@ -137,14 +151,16 @@ struct RedisTypeTraits<Int64>
std::string number = input.getline();
value = NumberParser::parse64(number);
}
};
template<>
struct RedisTypeTraits<std::string>
{
enum { TypeId = RedisType::REDIS_SIMPLE_STRING };
enum
{
TypeId = RedisType::REDIS_SIMPLE_STRING
};
static const char marker = '+';
@ -168,7 +184,10 @@ typedef Nullable<std::string> BulkString;
template<>
struct RedisTypeTraits<BulkString>
{
enum { TypeId = RedisType::REDIS_BULK_STRING };
enum
{
TypeId = RedisType::REDIS_BULK_STRING
};
static const char marker = '$';
@ -210,29 +229,28 @@ struct RedisTypeTraits<BulkString>
template<typename T>
class Type : public RedisType
class Type: public RedisType
/// Template class for all Redis types. This class will use
/// RedisTypeTraits structure for calling the type specific code.
{
public:
Type()
/// Constructor
/// Creates the Type.
{
}
Type(const T& t) : _value(t)
/// Constructor
/// Creates the Type from another one.
{
}
Type(const Type& copy) : _value(copy._value)
/// Copy Constructor
/// Creates the Type by copying another one.
{
}
virtual ~Type()
/// Destructor
/// Destroys the Type.
{
}
@ -267,10 +285,11 @@ public:
}
private:
T _value;
};
}} // Namespace Poco/Redis
} } // namespace Poco/Redis
#endif // Redis_Type_INCLUDED

View File

@ -9,14 +9,16 @@
//
// Implementation of the Array class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Array.h"
namespace Poco {
namespace Redis {
@ -26,7 +28,8 @@ Array::Array()
}
Array::Array(const Array& copy) : _elements(copy._elements)
Array::Array(const Array& copy):
_elements(copy._elements)
{
}
@ -48,9 +51,9 @@ Array& Array::addRedisType(RedisType::Ptr value)
int Array::getType(size_t pos) const
{
if ( _elements.isNull() ) throw NullValueException();
if (_elements.isNull()) throw NullValueException();
if ( pos >= _elements.value().size() ) throw InvalidArgumentException();
if (pos >= _elements.value().size()) throw InvalidArgumentException();
RedisType::Ptr element = _elements.value().at(pos);
return element->type();
@ -62,4 +65,5 @@ std::string Array::toString() const
return RedisTypeTraits<Array>::toString(*this);
}
} }
} } // namespace Poco::Redis

View File

@ -9,19 +9,22 @@
//
// Implementation of the AsyncReader class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/AsyncReader.h"
namespace Poco {
namespace Redis {
AsyncReader::AsyncReader(Client& client) : _client(client),
AsyncReader::AsyncReader(Client& client):
_client(client),
_activity(this, &AsyncReader::runActivity)
{
}
@ -35,7 +38,7 @@ AsyncReader::~AsyncReader()
void AsyncReader::runActivity()
{
while(!_activity.isStopped())
while (!_activity.isStopped())
{
try
{
@ -46,7 +49,7 @@ void AsyncReader::runActivity()
if ( args.isStopped() ) stop();
}
catch(Exception& e)
catch (Exception& e)
{
RedisEventArgs args(&e);
redisException.notify(this, args);
@ -57,4 +60,4 @@ void AsyncReader::runActivity()
}
} } // Poco::Redis
} } // namespace Poco::Redis

View File

@ -9,37 +9,55 @@
//
// Implementation of the Client class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Client.h"
#include "Poco/Redis/Exception.h"
namespace Poco {
namespace Redis {
Client::Client() : _address(), _socket(), _input(0), _output(0)
Client::Client():
_address(),
_socket(),
_input(0),
_output(0)
{
}
Client::Client(const std::string& hostAndPort) : _address(hostAndPort), _socket(), _input(0), _output(0)
Client::Client(const std::string& hostAndPort):
_address(hostAndPort),
_socket(),
_input(0),
_output(0)
{
connect();
}
Client::Client(const std::string& host, int port) : _address(host, port), _socket(), _input(0), _output(0)
Client::Client(const std::string& host, int port):
_address(host, port),
_socket(),
_input(0),
_output(0)
{
connect();
}
Client::Client(const Net::SocketAddress& addrs) : _address(addrs), _socket(), _input(0), _output(0)
Client::Client(const Net::SocketAddress& addrs):
_address(addrs),
_socket(),
_input(0),
_output(0)
{
connect();
}
@ -62,6 +80,7 @@ void Client::connect()
_output = new RedisOutputStream(_socket);
}
void Client::connect(const std::string& hostAndPort)
{
_address = Net::SocketAddress(hostAndPort);
@ -82,6 +101,7 @@ void Client::connect(const Net::SocketAddress& addrs)
connect();
}
void Client::connect(const Timespan& timeout)
{
poco_assert(! _input);
@ -92,6 +112,7 @@ void Client::connect(const Timespan& timeout)
_output = new RedisOutputStream(_socket);
}
void Client::connect(const std::string& hostAndPort, const Timespan& timeout)
{
_address = Net::SocketAddress(hostAndPort);
@ -112,6 +133,7 @@ void Client::connect(const Net::SocketAddress& addrs, const Timespan& timeout)
connect(timeout);
}
void Client::disconnect()
{
delete _input;
@ -123,6 +145,7 @@ void Client::disconnect()
_socket.close();
}
void Client::writeCommand(const Array& command, bool doFlush)
{
poco_assert(_output);
@ -130,16 +153,17 @@ void Client::writeCommand(const Array& command, bool doFlush)
std::string commandStr = command.toString();
_output->write(commandStr.c_str(), commandStr.length());
if ( doFlush ) _output->flush();
if (doFlush) _output->flush();
}
RedisType::Ptr Client::readReply()
{
poco_assert(_input);
int c = _input->get();
RedisType::Ptr result = RedisType::createRedisType(c);
if ( result.isNull() )
if (result.isNull())
{
throw RedisException("Invalid Redis type returned");
}
@ -149,23 +173,25 @@ RedisType::Ptr Client::readReply()
return result;
}
RedisType::Ptr Client::sendCommand(const Array& command)
{
writeCommand(command, true);
return readReply();
}
Array Client::sendCommands(const std::vector<Array>& commands)
{
Array results;
for(std::vector<Array>::const_iterator it = commands.begin(); it != commands.end(); ++it)
for (std::vector<Array>::const_iterator it = commands.begin(); it != commands.end(); ++it)
{
writeCommand(*it, false);
}
_output->flush();
for(int i = 0; i < commands.size(); ++i)
for (int i = 0; i < commands.size(); ++i)
{
results.addRedisType(readReply());
}
@ -173,4 +199,5 @@ Array Client::sendCommands(const std::vector<Array>& commands)
return results;
}
} } // Poco::Redis
} } // namespace Poco::Redis

View File

@ -9,31 +9,37 @@
//
// Implementation of the Command class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Command.h"
#include "Poco/NumberFormatter.h"
namespace Poco {
namespace Redis {
Command::Command(const std::string& command) : Array()
Command::Command(const std::string& command): Array()
{
add(command);
}
Command::Command(const Command& copy) : Array(copy)
Command::Command(const Command& copy): Array(copy)
{
}
Command::~Command()
{
}
Command Command::append(const std::string& key, const std::string& value)
{
Command cmd("APPEND");
@ -43,6 +49,7 @@ Command Command::append(const std::string& key, const std::string& value)
return cmd;
}
Command Command::blpop(const StringVec& lists, Int64 timeout)
{
Command cmd("BLPOP");
@ -52,6 +59,7 @@ Command Command::blpop(const StringVec& lists, Int64 timeout)
return cmd;
}
Command Command::brpop(const StringVec& lists, Int64 timeout)
{
Command cmd("BRPOP");
@ -61,6 +69,7 @@ Command Command::brpop(const StringVec& lists, Int64 timeout)
return cmd;
}
Command Command::brpoplpush(const std::string& sourceList, const std::string& destinationList, Int64 timeout)
{
Command cmd("BRPOPLPUSH");
@ -70,6 +79,7 @@ Command Command::brpoplpush(const std::string& sourceList, const std::string& de
return cmd;
}
Command Command::decr(const std::string& key, Int64 by)
{
Command cmd(by == 0 ? "DECR" : "DECRBY");
@ -80,6 +90,7 @@ Command Command::decr(const std::string& key, Int64 by)
return cmd;
}
Command Command::del(const std::string& key)
{
Command cmd("DEL");
@ -89,6 +100,7 @@ Command Command::del(const std::string& key)
return cmd;
}
Command Command::del(const StringVec& keys)
{
Command cmd("DEL");
@ -98,6 +110,7 @@ Command Command::del(const StringVec& keys)
return cmd;
}
Command Command::get(const std::string& key)
{
Command cmd("GET");
@ -107,6 +120,7 @@ Command Command::get(const std::string& key)
return cmd;
}
Command Command::hdel(const std::string& hash, const std::string& field)
{
Command cmd("HDEL");
@ -116,6 +130,7 @@ Command Command::hdel(const std::string& hash, const std::string& field)
return cmd;
}
Command Command::hdel(const std::string& hash, const StringVec& fields)
{
Command cmd("HDEL");
@ -125,6 +140,7 @@ Command Command::hdel(const std::string& hash, const StringVec& fields)
return cmd;
}
Command Command::hexists(const std::string& hash, const std::string& field)
{
Command cmd("HEXISTS");
@ -134,6 +150,7 @@ Command Command::hexists(const std::string& hash, const std::string& field)
return cmd;
}
Command Command::hget(const std::string& hash, const std::string& field)
{
Command cmd("HGET");
@ -143,6 +160,7 @@ Command Command::hget(const std::string& hash, const std::string& field)
return cmd;
}
Command Command::hgetall(const std::string& hash)
{
Command cmd("HGETALL");
@ -152,6 +170,7 @@ Command Command::hgetall(const std::string& hash)
return cmd;
}
Command Command::hincrby(const std::string& hash, const std::string& field, Int64 by)
{
Command cmd("HINCRBY");
@ -161,6 +180,7 @@ Command Command::hincrby(const std::string& hash, const std::string& field, Int6
return cmd;
}
Command Command::hkeys(const std::string& hash)
{
Command cmd("HKEYS");
@ -170,6 +190,7 @@ Command Command::hkeys(const std::string& hash)
return cmd;
}
Command Command::hlen(const std::string& hash)
{
Command cmd("HLEN");
@ -179,6 +200,7 @@ Command Command::hlen(const std::string& hash)
return cmd;
}
Command Command::hmget(const std::string& hash, const StringVec& fields)
{
Command cmd("HMGET");
@ -188,6 +210,7 @@ Command Command::hmget(const std::string& hash, const StringVec& fields)
return cmd;
}
Command Command::hmset(const std::string& hash, std::map<std::string, std::string>& fields)
{
Command cmd("HMSET");
@ -201,6 +224,7 @@ Command Command::hmset(const std::string& hash, std::map<std::string, std::strin
return cmd;
}
Command Command::hset(const std::string& hash, const std::string& field, const std::string& value, bool create)
{
Command cmd(create ? "HSET" : "HSETNX");
@ -210,11 +234,13 @@ Command Command::hset(const std::string& hash, const std::string& field, const s
return cmd;
}
Command Command::hset(const std::string& hash, const std::string& field, Int64 value, bool create)
{
return hset(hash, field, NumberFormatter::format(value), create);
}
Command Command::hstrlen(const std::string& hash, const std::string& field)
{
Command cmd("HSTRLEN");
@ -224,6 +250,7 @@ Command Command::hstrlen(const std::string& hash, const std::string& field)
return cmd;
}
Command Command::hvals(const std::string& hash)
{
Command cmd("HVALS");
@ -233,6 +260,7 @@ Command Command::hvals(const std::string& hash)
return cmd;
}
Command Command::incr(const std::string& key, Int64 by)
{
Command cmd(by == 0 ? "INCR" : "INCRBY");
@ -243,6 +271,7 @@ Command Command::incr(const std::string& key, Int64 by)
return cmd;
}
Command Command::lindex(const std::string& list, Int64 index)
{
Command cmd("LINDEX");
@ -252,6 +281,7 @@ Command Command::lindex(const std::string& list, Int64 index)
return cmd;
}
Command Command::linsert(const std::string& list, bool before, const std::string& reference, const std::string& value)
{
Command cmd("LINSERT");
@ -260,6 +290,7 @@ Command Command::linsert(const std::string& list, bool before, const std::string
return cmd;
}
Command Command::llen(const std::string& list)
{
Command cmd("LLEN");
@ -269,6 +300,7 @@ Command Command::llen(const std::string& list)
return cmd;
}
Command Command::lpop(const std::string& list)
{
Command cmd("LPOP");
@ -278,6 +310,7 @@ Command Command::lpop(const std::string& list)
return cmd;
}
Command Command::lpush(const std::string& list, const std::string& value, bool create)
{
Command cmd(create ? "LPUSH" : "LPUSHX");
@ -287,6 +320,7 @@ Command Command::lpush(const std::string& list, const std::string& value, bool c
return cmd;
}
Command Command::lpush(const std::string& list, const StringVec& values, bool create)
{
Command cmd(create ? "LPUSH" : "LPUSHX");
@ -296,6 +330,7 @@ Command Command::lpush(const std::string& list, const StringVec& values, bool cr
return cmd;
}
Command Command::lrange(const std::string& list, Int64 start, Int64 stop)
{
Command cmd("LRANGE");
@ -305,6 +340,7 @@ Command Command::lrange(const std::string& list, Int64 start, Int64 stop)
return cmd;
}
Command Command::lrem(const std::string& list, Int64 count, const std::string& value)
{
Command cmd("LREM");
@ -314,6 +350,7 @@ Command Command::lrem(const std::string& list, Int64 count, const std::string& v
return cmd;
}
Command Command::lset(const std::string& list, Int64 index, const std::string& value)
{
Command cmd("LSET");
@ -323,6 +360,7 @@ Command Command::lset(const std::string& list, Int64 index, const std::string& v
return cmd;
}
Command Command::ltrim(const std::string& list, Int64 start, Int64 stop)
{
Command cmd("LTRIM");
@ -332,6 +370,7 @@ Command Command::ltrim(const std::string& list, Int64 start, Int64 stop)
return cmd;
}
Command Command::mget(const StringVec& keys)
{
Command cmd("MGET");
@ -341,6 +380,7 @@ Command Command::mget(const StringVec& keys)
return cmd;
}
Command Command::mset(const std::map<std::string, std::string>& keyvalues, bool create)
{
Command cmd(create ? "MSET" : "MSETNX");
@ -353,6 +393,7 @@ Command Command::mset(const std::map<std::string, std::string>& keyvalues, bool
return cmd;
}
Command Command::sadd(const std::string& set, const std::string& value)
{
Command cmd("SADD");
@ -362,6 +403,7 @@ Command Command::sadd(const std::string& set, const std::string& value)
return cmd;
}
Command Command::sadd(const std::string& set, const StringVec& values)
{
Command cmd("SADD");
@ -371,6 +413,7 @@ Command Command::sadd(const std::string& set, const StringVec& values)
return cmd;
}
Command Command::scard(const std::string& set)
{
Command cmd("SCARD");
@ -380,6 +423,7 @@ Command Command::scard(const std::string& set)
return cmd;
}
Command Command::sdiff(const std::string& set1, const std::string& set2)
{
Command cmd("SDIFF");
@ -389,6 +433,7 @@ Command Command::sdiff(const std::string& set1, const std::string& set2)
return cmd;
}
Command Command::sdiff(const std::string& set, const StringVec& sets)
{
Command cmd("SDIFF");
@ -398,6 +443,7 @@ Command Command::sdiff(const std::string& set, const StringVec& sets)
return cmd;
}
Command Command::sdiffstore(const std::string& set, const std::string& set1, const std::string& set2)
{
Command cmd("SDIFFSTORE");
@ -407,6 +453,7 @@ Command Command::sdiffstore(const std::string& set, const std::string& set1, con
return cmd;
}
Command Command::sdiffstore(const std::string& set, const StringVec& sets)
{
Command cmd("SDIFFSTORE");
@ -416,6 +463,7 @@ Command Command::sdiffstore(const std::string& set, const StringVec& sets)
return cmd;
}
Command Command::set(const std::string& key, const std::string& value, bool overwrite, const Poco::Timespan& expireTime, bool create)
{
Command cmd("SET");
@ -428,11 +476,13 @@ Command Command::set(const std::string& key, const std::string& value, bool over
return cmd;
}
Command Command::set(const std::string& key, Int64 value, bool overwrite, const Poco::Timespan& expireTime, bool create)
{
return set(key, NumberFormatter::format(value), overwrite, expireTime, create);
}
Command Command::sinter(const std::string& set1, const std::string& set2)
{
Command cmd("SINTER");
@ -442,6 +492,7 @@ Command Command::sinter(const std::string& set1, const std::string& set2)
return cmd;
}
Command Command::sinter(const std::string& set, const StringVec& sets)
{
Command cmd("SINTER");
@ -451,6 +502,7 @@ Command Command::sinter(const std::string& set, const StringVec& sets)
return cmd;
}
Command Command::sinterstore(const std::string& set, const std::string& set1, const std::string& set2)
{
Command cmd("SINTERSTORE");
@ -460,6 +512,7 @@ Command Command::sinterstore(const std::string& set, const std::string& set1, co
return cmd;
}
Command Command::sinterstore(const std::string& set, const StringVec& sets)
{
Command cmd("SINTERSTORE");
@ -469,6 +522,7 @@ Command Command::sinterstore(const std::string& set, const StringVec& sets)
return cmd;
}
Command Command::sismember(const std::string& set, const std::string& member)
{
Command cmd("SISMEMBER");
@ -478,6 +532,7 @@ Command Command::sismember(const std::string& set, const std::string& member)
return cmd;
}
Command Command::smembers(const std::string& set)
{
Command cmd("SMEMBERS");
@ -487,6 +542,7 @@ Command Command::smembers(const std::string& set)
return cmd;
}
Command Command::smove(const std::string& source, const std::string& destination, const std::string& member)
{
Command cmd("SMOVE");
@ -496,6 +552,7 @@ Command Command::smove(const std::string& source, const std::string& destination
return cmd;
}
Command Command::spop(const std::string& set, Int64 count)
{
Command cmd("SPOP");
@ -506,6 +563,7 @@ Command Command::spop(const std::string& set, Int64 count)
return cmd;
}
Command Command::srandmember(const std::string& set, Int64 count)
{
Command cmd("SRANDMEMBER");
@ -516,6 +574,7 @@ Command Command::srandmember(const std::string& set, Int64 count)
return cmd;
}
Command Command::srem(const std::string& set1, const std::string& member)
{
Command cmd("SREM");
@ -525,6 +584,7 @@ Command Command::srem(const std::string& set1, const std::string& member)
return cmd;
}
Command Command::srem(const std::string& set, const StringVec& members)
{
Command cmd("SREM");
@ -534,6 +594,7 @@ Command Command::srem(const std::string& set, const StringVec& members)
return cmd;
}
Command Command::sunion(const std::string& set1, const std::string& set2)
{
Command cmd("SUNION");
@ -543,6 +604,7 @@ Command Command::sunion(const std::string& set1, const std::string& set2)
return cmd;
}
Command Command::sunion(const std::string& set, const StringVec& sets)
{
Command cmd("SUNION");
@ -552,6 +614,7 @@ Command Command::sunion(const std::string& set, const StringVec& sets)
return cmd;
}
Command Command::sunionstore(const std::string& set, const std::string& set1, const std::string& set2)
{
Command cmd("SUNIONSTORE");
@ -561,6 +624,7 @@ Command Command::sunionstore(const std::string& set, const std::string& set1, co
return cmd;
}
Command Command::sunionstore(const std::string& set, const StringVec& sets)
{
Command cmd("SUNIONSTORE");
@ -570,6 +634,7 @@ Command Command::sunionstore(const std::string& set, const StringVec& sets)
return cmd;
}
Command Command::rename(const std::string& key, const std::string& newName, bool overwrite)
{
Command cmd(overwrite ? "RENAME" : "RENAMENX");
@ -589,6 +654,7 @@ Command Command::rpop(const std::string& list)
return cmd;
}
Command Command::rpoplpush(const std::string& sourceList, const std::string& destinationList)
{
Command cmd("RPOPLPUSH");
@ -598,6 +664,7 @@ Command Command::rpoplpush(const std::string& sourceList, const std::string& des
return cmd;
}
Command Command::rpush(const std::string& list, const std::string& value, bool create)
{
Command cmd(create ? "RPUSH" : "RPUSHX");
@ -607,6 +674,7 @@ Command Command::rpush(const std::string& list, const std::string& value, bool c
return cmd;
}
Command Command::rpush(const std::string& list, const StringVec& values, bool create)
{
Command cmd(create ? "RPUSH" : "RPUSHX");
@ -617,4 +685,4 @@ Command Command::rpush(const std::string& list, const StringVec& values, bool cr
}
}} // Poco::Redis
} } // namespace Poco::Redis

View File

@ -9,27 +9,33 @@
//
// Implementation of the Error class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Error.h"
namespace Poco {
namespace Redis {
Error::Error()
{
}
Error::Error(const std::string& message) : _message(message)
Error::Error(const std::string& message): _message(message)
{
}
Error::~Error()
{
}
} }
} } // namespace Poco::Redis

View File

@ -9,17 +9,21 @@
//
// Implementation of the Exception class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Exception.h"
namespace Poco {
namespace Redis {
POCO_IMPLEMENT_EXCEPTION(RedisException, Exception, "Redis Exception")
}}
} } // namespace Poco::Redis

View File

@ -9,35 +9,40 @@
//
// Implementation of the RedisEventArgs class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/RedisEventArgs.h"
namespace Poco {
namespace Redis {
RedisEventArgs::RedisEventArgs(RedisType::Ptr pMessage) :
RedisEventArgs::RedisEventArgs(RedisType::Ptr pMessage):
_message(pMessage),
_exception(0),
_stop(false)
{
}
RedisEventArgs::RedisEventArgs(Exception* pException) :
RedisEventArgs::RedisEventArgs(Exception* pException):
_message(),
_exception(pException ? pException->clone() : 0),
_stop(false)
{
}
RedisEventArgs::~RedisEventArgs()
{
delete _exception;
}
}} // namespace Poco::Redis
} } // namespace Poco::Redis

View File

@ -9,18 +9,26 @@
//
// Implementation of the RedisStream class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include <iostream>
#include "Poco/Redis/RedisStream.h"
#include <iostream>
namespace Poco {
namespace Redis {
//
// RedisStreamBuf
//
RedisStreamBuf::RedisStreamBuf(Net::StreamSocket& redis):
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in | std::ios::out),
_redis(redis)
@ -44,6 +52,12 @@ int RedisStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
return _redis.sendBytes(buffer, length);
}
//
// RedisIOS
//
RedisIOS::RedisIOS(Net::StreamSocket& redis):
_buf(redis)
{
@ -74,6 +88,12 @@ void RedisIOS::close()
_buf.sync();
}
//
// RedisOutputStream
//
RedisOutputStream::RedisOutputStream(Net::StreamSocket& redis):
RedisIOS(redis),
std::ostream(&_buf)
@ -85,6 +105,7 @@ RedisOutputStream::~RedisOutputStream()
{
}
RedisInputStream::RedisInputStream(Net::StreamSocket& redis):
RedisIOS(redis),
std::istream(&_buf)
@ -92,10 +113,16 @@ RedisInputStream::RedisInputStream(Net::StreamSocket& redis):
}
//
// RedisInputStream
//
RedisInputStream::~RedisInputStream()
{
}
std::string RedisInputStream::getline()
{
std::string line;
@ -105,4 +132,4 @@ std::string RedisInputStream::getline()
}
}}
} } // namespace Poco::Redis

View File

@ -9,16 +9,18 @@
//
// Implementation of the Type class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Type.h"
#include "Poco/Redis/Error.h"
#include "Poco/Redis/Array.h"
namespace Poco {
namespace Redis {
@ -27,6 +29,7 @@ RedisType::RedisType()
{
}
RedisType::~RedisType()
{
}
@ -38,24 +41,24 @@ RedisType::Ptr RedisType::createRedisType(char marker)
switch(marker)
{
case RedisTypeTraits<Int64>::marker :
result = new Type<Int64>();
break;
case RedisTypeTraits<std::string>::marker :
result = new Type<std::string>();
break;
case RedisTypeTraits<BulkString>::marker :
result = new Type<BulkString>();
break;
case RedisTypeTraits<Array>::marker :
result = new Type<Array>();
break;
case RedisTypeTraits<Error>::marker :
result = new Type<Error>();
break;
case RedisTypeTraits<Int64>::marker :
result = new Type<Int64>();
break;
case RedisTypeTraits<std::string>::marker :
result = new Type<std::string>();
break;
case RedisTypeTraits<BulkString>::marker :
result = new Type<BulkString>();
break;
case RedisTypeTraits<Array>::marker :
result = new Type<Array>();
break;
case RedisTypeTraits<Error>::marker :
result = new Type<Error>();
break;
}
return result;
}
}}
} } // namespace Poco::Redis

View File

@ -5,7 +5,7 @@
//
// Console-based test driver for Poco MongoDB.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
//
// Definition of the RedisTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
@ -18,7 +18,6 @@
#include "Poco/Redis/Redis.h"
#include "Poco/Redis/Client.h"
#include "Poco/CppUnit/TestCase.h"

View File

@ -3,7 +3,7 @@
//
// $Id$
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0

View File

@ -5,7 +5,7 @@
//
// Definition of the RedisTestSuite class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0

View File

@ -5,7 +5,7 @@
//
// Console-based test driver for Windows CE.
//
// Copyright (c) 2004-2010, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0

View File

@ -5,7 +5,7 @@
//
// Windows test driver for Poco MongoDB.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0