diff --git a/Redis/include/Poco/Redis/Array.h b/Redis/include/Poco/Redis/Array.h index f42dd4b6b..f7c0496d9 100644 --- a/Redis/include/Poco/Redis/Array.h +++ b/Redis/include/Poco/Redis/Array.h @@ -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 -#include #include "Poco/Redis/Redis.h" #include "Poco/Redis/Type.h" #include "Poco/Redis/Exception.h" +#include +#include + 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::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 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& 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 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& 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 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 > _elements; - void checkNull(); /// Checks for null array and sets a new vector if true. + + Nullable > _elements; }; + +// +// inlines +// + + inline Array& Array::operator<<(const char* s) { BulkString value(s); return add(value); } + inline Array& Array::operator<<(const std::vector& 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& strings) { for(std::vector::const_iterator it = strings.begin(); it != strings.end(); ++it) @@ -193,22 +212,26 @@ inline Array& Array::add(const std::vector& strings) return *this; } + inline Array& Array::addSimpleString(const std::string& value) { return addRedisType(new Type(value)); } + inline Array::const_iterator Array::begin() const { return _elements.value().begin(); } + inline void Array::checkNull() { std::vector 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 }; -}} +} } // namespace Poco::Redis + #endif // Redis_Array_INCLUDED diff --git a/Redis/include/Poco/Redis/AsyncReader.h b/Redis/include/Poco/Redis/AsyncReader.h index 2a7e3a996..d6ca8ba04 100644 --- a/Redis/include/Poco/Redis/AsyncReader.h +++ b/Redis/include/Poco/Redis/AsyncReader.h @@ -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 redisResponse; - /// Event that is called when a message is received + /// Event that is fired when a message is received. + BasicEvent 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 diff --git a/Redis/include/Poco/Redis/Client.h b/Redis/include/Poco/Redis/Client.h index eba4b10f1..c9e1eab98 100644 --- a/Redis/include/Poco/Redis/Client.h +++ b/Redis/include/Poco/Redis/Client.h @@ -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. This is /// because a bulk string can represent a Null value. /// - /// BulkString bs = client.execute(...); - /// if ( bs.isNull() ) - /// { - /// // We have a Null value - /// } - /// else - /// { - /// // We have a string value - /// } + /// BulkString bs = client.execute(...); + /// 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 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(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 diff --git a/Redis/include/Poco/Redis/Command.h b/Redis/include/Poco/Redis/Command.h index 2c67b871d..69e057063 100644 --- a/Redis/include/Poco/Redis/Command.h +++ b/Redis/include/Poco/Redis/Command.h @@ -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 #include + 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 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& 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& 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 diff --git a/Redis/include/Poco/Redis/Error.h b/Redis/include/Poco/Redis/Error.h index fd1edc7ce..92cc53387 100644 --- a/Redis/include/Poco/Redis/Error.h +++ b/Redis/include/Poco/Redis/Error.h @@ -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 { @@ -76,6 +86,8 @@ struct RedisTypeTraits } }; -}} // Namespace Poco::Redis -#endif // Redis_Error_INCLUDED \ No newline at end of file +} } // namespace Poco::Redis + + +#endif // Redis_Error_INCLUDED diff --git a/Redis/include/Poco/Redis/Exception.h b/Redis/include/Poco/Redis/Exception.h index d45d85348..1ed6b4f7b 100644 --- a/Redis/include/Poco/Redis/Exception.h +++ b/Redis/include/Poco/Redis/Exception.h @@ -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 #include "Poco/Exception.h" +#include + namespace Poco { namespace Redis { + POCO_DECLARE_EXCEPTION(Redis_API, RedisException, Exception) -}} + +} } // namespace Poco::Redis + #endif // Redis_Exception_INCLUDED diff --git a/Redis/include/Poco/Redis/PoolableConnectionFactory.h b/Redis/include/Poco/Redis/PoolableConnectionFactory.h index edc9d46af..a2dfd0441 100644 --- a/Redis/include/Poco/Redis/PoolableConnectionFactory.h +++ b/Redis/include/Poco/Redis/PoolableConnectionFactory.h @@ -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 /// 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& 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 diff --git a/Redis/include/Poco/Redis/Redis.h b/Redis/include/Poco/Redis/Redis.h index a25cd1598..04c64fe48 100644 --- a/Redis/include/Poco/Redis/Redis.h +++ b/Redis/include/Poco/Redis/Redis.h @@ -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) diff --git a/Redis/include/Poco/Redis/RedisEventArgs.h b/Redis/include/Poco/Redis/RedisEventArgs.h index eca6c9877..689f3298e 100644 --- a/Redis/include/Poco/Redis/RedisEventArgs.h +++ b/Redis/include/Poco/Redis/RedisEventArgs.h @@ -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 diff --git a/Redis/include/Poco/Redis/RedisStream.h b/Redis/include/Poco/Redis/RedisStream.h index 353620a3e..bb1989476 100644 --- a/Redis/include/Poco/Redis/RedisStream.h +++ b/Redis/include/Poco/Redis/RedisStream.h @@ -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 #include + 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 \ No newline at end of file + +#endif // Redis_RedisStream_INCLUDED diff --git a/Redis/include/Poco/Redis/Type.h b/Redis/include/Poco/Redis/Type.h index b926c89a3..83608090b 100644 --- a/Redis/include/Poco/Redis/Type.h +++ b/Redis/include/Poco/Redis/Type.h @@ -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 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 struct RedisTypeTraits { @@ -123,7 +134,10 @@ struct RedisTypeTraits template<> struct RedisTypeTraits { - enum { TypeId = RedisType::REDIS_INTEGER }; + enum + { + TypeId = RedisType::REDIS_INTEGER + }; static const char marker = ':'; @@ -137,14 +151,16 @@ struct RedisTypeTraits std::string number = input.getline(); value = NumberParser::parse64(number); } - }; template<> struct RedisTypeTraits { - enum { TypeId = RedisType::REDIS_SIMPLE_STRING }; + enum + { + TypeId = RedisType::REDIS_SIMPLE_STRING + }; static const char marker = '+'; @@ -168,7 +184,10 @@ typedef Nullable BulkString; template<> struct RedisTypeTraits { - enum { TypeId = RedisType::REDIS_BULK_STRING }; + enum + { + TypeId = RedisType::REDIS_BULK_STRING + }; static const char marker = '$'; @@ -210,29 +229,28 @@ struct RedisTypeTraits template -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 diff --git a/Redis/src/Array.cpp b/Redis/src/Array.cpp index 961ba3059..5d93ac679 100644 --- a/Redis/src/Array.cpp +++ b/Redis/src/Array.cpp @@ -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::toString(*this); } -} } + +} } // namespace Poco::Redis diff --git a/Redis/src/AsyncReader.cpp b/Redis/src/AsyncReader.cpp index 41a3ebcba..9030a7ac5 100644 --- a/Redis/src/AsyncReader.cpp +++ b/Redis/src/AsyncReader.cpp @@ -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 diff --git a/Redis/src/Client.cpp b/Redis/src/Client.cpp index e38b164f3..a53a97b28 100644 --- a/Redis/src/Client.cpp +++ b/Redis/src/Client.cpp @@ -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& commands) { Array results; - for(std::vector::const_iterator it = commands.begin(); it != commands.end(); ++it) + for (std::vector::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& commands) return results; } -} } // Poco::Redis + +} } // namespace Poco::Redis diff --git a/Redis/src/Command.cpp b/Redis/src/Command.cpp index 0705b3c48..656c0d475 100644 --- a/Redis/src/Command.cpp +++ b/Redis/src/Command.cpp @@ -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& fields) { Command cmd("HMSET"); @@ -201,6 +224,7 @@ Command Command::hmset(const std::string& hash, std::map& keyvalues, bool create) { Command cmd(create ? "MSET" : "MSETNX"); @@ -353,6 +393,7 @@ Command Command::mset(const std::map& 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 diff --git a/Redis/src/Error.cpp b/Redis/src/Error.cpp index 51c9f7a40..daab8c567 100644 --- a/Redis/src/Error.cpp +++ b/Redis/src/Error.cpp @@ -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() { } -} } \ No newline at end of file + +} } // namespace Poco::Redis diff --git a/Redis/src/Exception.cpp b/Redis/src/Exception.cpp index c27e5743c..75f252b02 100644 --- a/Redis/src/Exception.cpp +++ b/Redis/src/Exception.cpp @@ -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 diff --git a/Redis/src/RedisEventArgs.cpp b/Redis/src/RedisEventArgs.cpp index 1f7979978..e1d4fa5e8 100644 --- a/Redis/src/RedisEventArgs.cpp +++ b/Redis/src/RedisEventArgs.cpp @@ -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 diff --git a/Redis/src/RedisStream.cpp b/Redis/src/RedisStream.cpp index b794bb210..68d317bd1 100644 --- a/Redis/src/RedisStream.cpp +++ b/Redis/src/RedisStream.cpp @@ -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 + + #include "Poco/Redis/RedisStream.h" +#include + 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() } -}} \ No newline at end of file +} } // namespace Poco::Redis diff --git a/Redis/src/Type.cpp b/Redis/src/Type.cpp index 68ce05a90..382428d09 100644 --- a/Redis/src/Type.cpp +++ b/Redis/src/Type.cpp @@ -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::marker : - result = new Type(); - break; - case RedisTypeTraits::marker : - result = new Type(); - break; - case RedisTypeTraits::marker : - result = new Type(); - break; - case RedisTypeTraits::marker : - result = new Type(); - break; - case RedisTypeTraits::marker : - result = new Type(); - break; + case RedisTypeTraits::marker : + result = new Type(); + break; + case RedisTypeTraits::marker : + result = new Type(); + break; + case RedisTypeTraits::marker : + result = new Type(); + break; + case RedisTypeTraits::marker : + result = new Type(); + break; + case RedisTypeTraits::marker : + result = new Type(); + break; } return result; } -}} \ No newline at end of file +} } // namespace Poco::Redis diff --git a/Redis/testsuite/src/Driver.cpp b/Redis/testsuite/src/Driver.cpp index fa0c9001d..0ef1639b5 100644 --- a/Redis/testsuite/src/Driver.cpp +++ b/Redis/testsuite/src/Driver.cpp @@ -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 diff --git a/Redis/testsuite/src/RedisTest.cpp b/Redis/testsuite/src/RedisTest.cpp index 284f7fd36..dc428ad7c 100644 --- a/Redis/testsuite/src/RedisTest.cpp +++ b/Redis/testsuite/src/RedisTest.cpp @@ -3,24 +3,24 @@ // // $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 // -#include + #include "Poco/Exception.h" #include "Poco/Delegate.h" #include "Poco/Thread.h" - #include "RedisTest.h" #include "Poco/Redis/AsyncReader.h" #include "Poco/Redis/Command.h" #include "Poco/Redis/PoolableConnectionFactory.h" - #include "Poco/CppUnit/TestCaller.h" #include "Poco/CppUnit/TestSuite.h" +#include + using namespace Poco::Redis; @@ -64,7 +64,6 @@ RedisTest::~RedisTest() void RedisTest::setUp() { - } @@ -89,11 +88,11 @@ void RedisTest::testAPPEND() std::string result = _redis.execute(setCommand); assert(result.compare("OK") == 0); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } @@ -104,11 +103,11 @@ void RedisTest::testAPPEND() Poco::Int64 result = _redis.execute(appendCommand); assert(result == 11); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } @@ -119,16 +118,17 @@ void RedisTest::testAPPEND() BulkString result = _redis.execute(getCommand); assert(result.value().compare("Hello World") == 0); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } } + void RedisTest::testBLPOP() { if (!_connected) @@ -146,11 +146,11 @@ void RedisTest::testBLPOP() { _redis.execute(delCommand); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } @@ -166,7 +166,7 @@ void RedisTest::testBLPOP() Poco::Int64 result = _redis.execute(rpush); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -179,12 +179,13 @@ void RedisTest::testBLPOP() assert(result.get(0).value().compare("list1") == 0); assert(result.get(1).value().compare("a") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testBRPOP() { if (!_connected) @@ -202,11 +203,11 @@ void RedisTest::testBRPOP() { _redis.execute(delCommand); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } @@ -222,7 +223,7 @@ void RedisTest::testBRPOP() Poco::Int64 result = _redis.execute(rpush); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -235,12 +236,13 @@ void RedisTest::testBRPOP() assert(result.get(0).value().compare("list1") == 0); assert(result.get(1).value().compare("c") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testDECR() { if (!_connected) @@ -255,7 +257,7 @@ void RedisTest::testDECR() std::string result = _redis.execute(set); assert(result.compare("OK") == 0); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } @@ -266,7 +268,7 @@ void RedisTest::testDECR() Poco::Int64 result = _redis.execute(decr); assert(result == 9); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } @@ -277,7 +279,7 @@ void RedisTest::testDECR() std::string result = _redis.execute(set); assert(result.compare("OK") == 0); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } @@ -287,13 +289,14 @@ void RedisTest::testDECR() Poco::Int64 result = _redis.execute(decr); fail("This must fail"); } - catch(RedisException& e) + catch (RedisException& e) { // ERR value is not an integer or out of range } } + void RedisTest::testECHO() { if (!_connected) @@ -312,12 +315,13 @@ void RedisTest::testECHO() assert(!result.isNull()); assert(result.value().compare("Hello World") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testError() { if (!_connected) @@ -334,12 +338,13 @@ void RedisTest::testError() BulkString result = _redis.execute(command); fail("Invalid command must throw RedisException"); } - catch(RedisException &e) + catch (RedisException& e) { // Must fail } } + void RedisTest::testEVAL() { if (!_connected) @@ -368,13 +373,14 @@ void RedisTest::testEVAL() BulkString s = a.get(1); assert(s.value().compare("Hello World!") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testHDEL() { if (!_connected) @@ -391,7 +397,7 @@ void RedisTest::testHDEL() Poco::Int64 value = _redis.execute(hset); assert(value == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -402,7 +408,7 @@ void RedisTest::testHDEL() Poco::Int64 result = _redis.execute(hdel); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -413,12 +419,13 @@ void RedisTest::testHDEL() Poco::Int64 result = _redis.execute(hdel); assert(result == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testHEXISTS() { if (!_connected) @@ -435,7 +442,7 @@ void RedisTest::testHEXISTS() Poco::Int64 value = _redis.execute(hset); assert(value == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -446,7 +453,7 @@ void RedisTest::testHEXISTS() Poco::Int64 result = _redis.execute(hexists); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -457,12 +464,13 @@ void RedisTest::testHEXISTS() Poco::Int64 result = _redis.execute(hexists); assert(result == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testHGETALL() { if (!_connected) @@ -479,7 +487,7 @@ void RedisTest::testHGETALL() Poco::Int64 value = _redis.execute(hset); assert(value == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -490,7 +498,7 @@ void RedisTest::testHGETALL() Poco::Int64 value = _redis.execute(hset); assert(value == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -501,12 +509,13 @@ void RedisTest::testHGETALL() Array result = _redis.execute(hgetall); assert(result.size() == 4); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testHINCRBY() { if (!_connected) @@ -523,7 +532,7 @@ void RedisTest::testHINCRBY() Poco::Int64 value = _redis.execute(hset); assert(value == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -534,7 +543,7 @@ void RedisTest::testHINCRBY() Poco::Int64 n = _redis.execute(hincrby); assert(n == 6); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -545,7 +554,7 @@ void RedisTest::testHINCRBY() Poco::Int64 n = _redis.execute(hincrby); assert(n == 5); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -556,12 +565,13 @@ void RedisTest::testHINCRBY() Poco::Int64 n = _redis.execute(hincrby); assert(n == -5); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testHKEYS() { if (!_connected) @@ -578,7 +588,7 @@ void RedisTest::testHKEYS() Poco::Int64 value = _redis.execute(hset); assert(value == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -589,7 +599,7 @@ void RedisTest::testHKEYS() Poco::Int64 value = _redis.execute(hset); assert(value == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -600,7 +610,7 @@ void RedisTest::testHKEYS() Poco::Int64 value = _redis.execute(hlen); assert(value == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -613,12 +623,13 @@ void RedisTest::testHKEYS() assert(result.get(0).value().compare("field1") == 0); assert(result.get(1).value().compare("field2") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testHMGET() { if (!_connected) @@ -635,7 +646,7 @@ void RedisTest::testHMGET() Poco::Int64 value = _redis.execute(hset); assert(value == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -646,7 +657,7 @@ void RedisTest::testHMGET() Poco::Int64 value = _redis.execute(hset); assert(value == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -665,12 +676,13 @@ void RedisTest::testHMGET() assert(result.get(1).value().compare("World") == 0); assert(result.get(2).isNull()); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testHSET() { if (!_connected) @@ -687,7 +699,7 @@ void RedisTest::testHSET() Poco::Int64 value = _redis.execute(hset); assert(value == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -698,12 +710,13 @@ void RedisTest::testHSET() BulkString s = _redis.execute(hget); assert(s.value().compare("Hello") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testHMSET() { if (!_connected) @@ -724,7 +737,7 @@ void RedisTest::testHMSET() std::string result = _redis.execute(hmset); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -735,7 +748,7 @@ void RedisTest::testHMSET() BulkString s = _redis.execute(hget); assert(s.value().compare("Hello") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -746,13 +759,14 @@ void RedisTest::testHMSET() BulkString s = _redis.execute(hget); assert(s.value().compare("World") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testHSTRLEN() { if (!_connected) @@ -774,7 +788,7 @@ void RedisTest::testHSTRLEN() std::string result = _redis.execute(hmset); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -785,7 +799,7 @@ void RedisTest::testHSTRLEN() Poco::Int64 len = _redis.execute(hstrlen); assert(len == 10); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -796,7 +810,7 @@ void RedisTest::testHSTRLEN() Poco::Int64 len = _redis.execute(hstrlen); assert(len == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -807,12 +821,13 @@ void RedisTest::testHSTRLEN() Poco::Int64 len = _redis.execute(hstrlen); assert(len == 4); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testHVALS() { if (!_connected) @@ -833,7 +848,7 @@ void RedisTest::testHVALS() std::string result = _redis.execute(hmset); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -846,12 +861,13 @@ void RedisTest::testHVALS() assert(result.get(0).value().compare("Hello") == 0); assert(result.get(1).value().compare("World") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testINCR() { if (!_connected) @@ -867,7 +883,7 @@ void RedisTest::testINCR() std::string result = _redis.execute(command); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -878,12 +894,13 @@ void RedisTest::testINCR() Poco::Int64 value = _redis.execute(command); assert(value == 11); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testINCRBY() { if (!_connected) @@ -899,7 +916,7 @@ void RedisTest::testINCRBY() std::string result = _redis.execute(command); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -910,12 +927,13 @@ void RedisTest::testINCRBY() Poco::Int64 value = _redis.execute(command); assert(value == 15); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testPING() { if (!_connected) @@ -933,7 +951,7 @@ void RedisTest::testPING() std::string result = _redis.execute(command); assert(result.compare("PONG") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -946,13 +964,14 @@ void RedisTest::testPING() assert(!result.isNull()); assert(result.value().compare("Hello") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testLPOP() { if (!_connected) @@ -978,7 +997,7 @@ void RedisTest::testLPOP() result = _redis.execute(rpush); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -989,7 +1008,7 @@ void RedisTest::testLPOP() BulkString result = _redis.execute(lpop); assert(result.value().compare("one") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1003,17 +1022,18 @@ void RedisTest::testLPOP() assert(result.get(0).value().compare("two") == 0); assert(result.get(1).value().compare("three") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::NullValueException &e) + catch (Poco::NullValueException& e) { fail(e.message()); } } + void RedisTest::testLSET() { if (!_connected) @@ -1039,7 +1059,7 @@ void RedisTest::testLSET() result = _redis.execute(rpush); assert(result == 3); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } @@ -1049,7 +1069,7 @@ void RedisTest::testLSET() { std::string result = _redis.execute(lset); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } @@ -1059,7 +1079,7 @@ void RedisTest::testLSET() { std::string result = _redis.execute(lset); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } @@ -1074,16 +1094,18 @@ void RedisTest::testLSET() assert(result.get(1).value().compare("five") == 0); assert(result.get(2).value().compare("three") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::NullValueException &e) + catch (Poco::NullValueException& e) { fail(e.message()); } } + + void RedisTest::testLINDEX() { if (!_connected) @@ -1105,7 +1127,7 @@ void RedisTest::testLINDEX() result = _redis.execute(lpush); assert(result == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1116,12 +1138,13 @@ void RedisTest::testLINDEX() BulkString result = _redis.execute(lindex); assert(result.value().compare("Hello") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testLINSERT() { if (!_connected) @@ -1155,20 +1178,21 @@ void RedisTest::testLINSERT() assert(range.get(1).value().compare("There") == 0); assert(range.get(2).value().compare("World") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException &e) + catch (Poco::BadCastException& e) { fail(e.message()); } - catch(Poco::NullValueException &e) + catch (Poco::NullValueException& e) { fail(e.message()); } } + void RedisTest::testLREM() { if (!_connected) @@ -1191,7 +1215,7 @@ void RedisTest::testLREM() Poco::Int64 result = _redis.execute(rpush); assert(result == 4); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1202,11 +1226,11 @@ void RedisTest::testLREM() Poco::Int64 n = _redis.execute(lrem); assert(n == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } @@ -1220,16 +1244,17 @@ void RedisTest::testLREM() assert(result.get(0).value().compare("hello") == 0); assert(result.get(1).value().compare("foo") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::NullValueException &e) + catch (Poco::NullValueException& e) { fail(e.message()); } } + void RedisTest::testLTRIM() { if (!_connected) @@ -1255,7 +1280,7 @@ void RedisTest::testLTRIM() result = _redis.execute(rpush); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1266,7 +1291,7 @@ void RedisTest::testLTRIM() std::string result = _redis.execute(ltrim); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1280,17 +1305,18 @@ void RedisTest::testLTRIM() assert(result.get(0).value().compare("two") == 0); assert(result.get(1).value().compare("three") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::NullValueException &e) + catch (Poco::NullValueException& e) { fail(e.message()); } } + void RedisTest::testMSET() { if (!_connected) @@ -1308,7 +1334,7 @@ void RedisTest::testMSET() std::string result = _redis.execute(command); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1332,16 +1358,17 @@ void RedisTest::testMSET() value = result.get(2); assert(value.isNull()); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } } + void RedisTest::testMSETWithMap() { if (!_connected) @@ -1362,7 +1389,7 @@ void RedisTest::testMSETWithMap() std::string result = _redis.execute(mset); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1387,16 +1414,17 @@ void RedisTest::testMSETWithMap() value = result.get(2); assert(value.isNull()); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } } + void RedisTest::testMULTI() { if (!_connected) @@ -1416,11 +1444,11 @@ void RedisTest::testMULTI() std::string result = _redis.execute(command); assert(result.compare("OK") == 0); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } @@ -1433,11 +1461,11 @@ void RedisTest::testMULTI() std::string result = _redis.execute(command); assert(result.compare("QUEUED") == 0); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } @@ -1450,11 +1478,11 @@ void RedisTest::testMULTI() std::string result = _redis.execute(command); assert(result.compare("QUEUED") == 0); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } @@ -1471,16 +1499,17 @@ void RedisTest::testMULTI() v = result.get(1); assert(v == 1); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } } + void RedisTest::testPipeliningWithSendCommands() { if (!_connected) @@ -1502,20 +1531,21 @@ void RedisTest::testPipeliningWithSendCommands() assert(result.size() == 2); // The 2 results must be simple PONG strings - for(size_t i = 0; i < 2; ++i) + for (size_t i = 0; i < 2; ++i) { try { std::string pong = result.get(i); assert(pong.compare("PONG") == 0); } - catch(...) + catch (...) { fail("An exception occurred"); } } } + void RedisTest::testPipeliningWithWriteCommand() { if (!_connected) @@ -1532,7 +1562,7 @@ void RedisTest::testPipeliningWithWriteCommand() _redis.flush(); // We expect 2 results with simple "PONG" strings - for(int i = 0; i < 2; ++i) + for (int i = 0; i < 2; ++i) { std::string pong; try @@ -1540,33 +1570,33 @@ void RedisTest::testPipeliningWithWriteCommand() _redis.readReply(pong); assert(pong.compare("PONG") == 0); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } } } + class RedisSubscriber { public: - void onMessage(const void* pSender, RedisEventArgs& args) { - if ( ! args.message().isNull() ) + if (!args.message().isNull()) { Type* arrayType = dynamic_cast*>(args.message().get()); - if ( arrayType != NULL ) + if (arrayType != NULL) { Array& array = arrayType->value(); - if ( array.size() == 3 ) + if (array.size() == 3) { BulkString type = array.get(0); - if ( type.value().compare("unsubscribe") == 0 ) + if (type.value().compare("unsubscribe") == 0) { Poco::Int64 n = array.get(2); // When 0, no subscribers anymore, so stop reading ... - if ( n == 0 ) args.stop(); + if (n == 0) args.stop(); } } else @@ -1589,9 +1619,9 @@ public: // No need to call stop, AsyncReader stops automatically when an // exception is received. } - }; + void RedisTest::testPubSub() { if (!_connected) @@ -1623,6 +1653,7 @@ void RedisTest::testPubSub() _redis.flush(); } + void RedisTest::testSADD() { if (!_connected) @@ -1639,7 +1670,7 @@ void RedisTest::testSADD() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1650,7 +1681,7 @@ void RedisTest::testSADD() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1661,12 +1692,13 @@ void RedisTest::testSADD() Poco::Int64 result = _redis.execute(sadd); assert(result == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSCARD() { if (!_connected) @@ -1683,7 +1715,7 @@ void RedisTest::testSCARD() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1694,7 +1726,7 @@ void RedisTest::testSCARD() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1705,12 +1737,13 @@ void RedisTest::testSCARD() Poco::Int64 result = _redis.execute(scard); assert(result == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSDIFF() { if (!_connected) @@ -1732,7 +1765,7 @@ void RedisTest::testSDIFF() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1747,7 +1780,7 @@ void RedisTest::testSDIFF() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1758,12 +1791,13 @@ void RedisTest::testSDIFF() Array result = _redis.execute(sdiff); assert(result.size() == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSDIFFSTORE() { if (!_connected) @@ -1786,7 +1820,7 @@ void RedisTest::testSDIFFSTORE() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1801,7 +1835,7 @@ void RedisTest::testSDIFFSTORE() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1812,7 +1846,7 @@ void RedisTest::testSDIFFSTORE() Poco::Int64 result = _redis.execute(sdiffstore); assert(result == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1823,12 +1857,13 @@ void RedisTest::testSDIFFSTORE() Array result = _redis.execute(smembers); assert(result.size() == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSET() { if (!_connected) @@ -1846,7 +1881,7 @@ void RedisTest::testSET() std::string result = _redis.execute(command); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1859,7 +1894,7 @@ void RedisTest::testSET() BulkString result = _redis.execute(command); assert(result.isNull()); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1887,7 +1922,7 @@ void RedisTest::testSINTER() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1902,7 +1937,7 @@ void RedisTest::testSINTER() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1914,12 +1949,13 @@ void RedisTest::testSINTER() assert(result.size() == 1); assert(result.get(0).value().compare("c") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSINTERSTORE() { if (!_connected) @@ -1942,7 +1978,7 @@ void RedisTest::testSINTERSTORE() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1957,7 +1993,7 @@ void RedisTest::testSINTERSTORE() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1968,7 +2004,7 @@ void RedisTest::testSINTERSTORE() Poco::Int64 result = _redis.execute(sinterstore); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -1980,12 +2016,13 @@ void RedisTest::testSINTERSTORE() assert(result.size() == 1); assert(result.get(0).value().compare("c") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSISMEMBER() { if (!_connected) @@ -2002,7 +2039,7 @@ void RedisTest::testSISMEMBER() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2013,7 +2050,7 @@ void RedisTest::testSISMEMBER() Poco::Int64 result = _redis.execute(sismember); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2024,12 +2061,13 @@ void RedisTest::testSISMEMBER() Poco::Int64 result = _redis.execute(sismember); assert(result == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSMEMBERS() { if (!_connected) @@ -2046,7 +2084,7 @@ void RedisTest::testSMEMBERS() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2057,7 +2095,7 @@ void RedisTest::testSMEMBERS() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2068,12 +2106,13 @@ void RedisTest::testSMEMBERS() Array result = _redis.execute(smembers); assert(result.size() == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSMOVE() { if (!_connected) @@ -2091,7 +2130,7 @@ void RedisTest::testSMOVE() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2102,7 +2141,7 @@ void RedisTest::testSMOVE() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2113,7 +2152,7 @@ void RedisTest::testSMOVE() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2124,7 +2163,7 @@ void RedisTest::testSMOVE() Poco::Int64 result = _redis.execute(smove); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2136,7 +2175,7 @@ void RedisTest::testSMOVE() assert(result.size() == 1); assert(result.get(0).value().compare("one") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2147,12 +2186,13 @@ void RedisTest::testSMOVE() Array result = _redis.execute(smembers); assert(result.size() == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSPOP() { if (!_connected) @@ -2169,7 +2209,7 @@ void RedisTest::testSPOP() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2180,7 +2220,7 @@ void RedisTest::testSPOP() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2191,7 +2231,7 @@ void RedisTest::testSPOP() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2202,7 +2242,7 @@ void RedisTest::testSPOP() BulkString result = _redis.execute(spop); assert(!result.isNull()); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2213,7 +2253,7 @@ void RedisTest::testSPOP() Array result = _redis.execute(smembers); assert(result.size() == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2224,7 +2264,7 @@ void RedisTest::testSPOP() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2235,7 +2275,7 @@ void RedisTest::testSPOP() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2247,13 +2287,14 @@ void RedisTest::testSPOP() Array result = _redis.execute(spop); assert(result.size() == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } */ } + void RedisTest::testSRANDMEMBER() { if (!_connected) @@ -2275,7 +2316,7 @@ void RedisTest::testSRANDMEMBER() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2286,7 +2327,7 @@ void RedisTest::testSRANDMEMBER() BulkString result = _redis.execute(srandmember); assert(!result.isNull()); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2297,7 +2338,7 @@ void RedisTest::testSRANDMEMBER() Array result = _redis.execute(srandmember); assert(result.size() == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2308,12 +2349,13 @@ void RedisTest::testSRANDMEMBER() Array result = _redis.execute(srandmember); assert(result.size() == 5); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSTRLEN() { if (!_connected) @@ -2331,7 +2373,7 @@ void RedisTest::testSTRLEN() std::string result = _redis.execute(command); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2346,12 +2388,13 @@ void RedisTest::testSTRLEN() assert(result == 11); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSREM() { if (!_connected) @@ -2368,7 +2411,7 @@ void RedisTest::testSREM() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2378,7 +2421,7 @@ void RedisTest::testSREM() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2388,7 +2431,7 @@ void RedisTest::testSREM() Poco::Int64 result = _redis.execute(sadd); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2399,7 +2442,7 @@ void RedisTest::testSREM() Poco::Int64 result = _redis.execute(srem); assert(result == 1); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2410,7 +2453,7 @@ void RedisTest::testSREM() Poco::Int64 result = _redis.execute(srem); assert(result == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2421,12 +2464,13 @@ void RedisTest::testSREM() Array result = _redis.execute(smembers); assert(result.size() == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSUNION() { if (!_connected) @@ -2448,7 +2492,7 @@ void RedisTest::testSUNION() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2463,7 +2507,7 @@ void RedisTest::testSUNION() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2474,12 +2518,13 @@ void RedisTest::testSUNION() Array result = _redis.execute(sunion); assert(result.size() == 5); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testSUNIONSTORE() { if (!_connected) @@ -2502,7 +2547,7 @@ void RedisTest::testSUNIONSTORE() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2517,7 +2562,7 @@ void RedisTest::testSUNIONSTORE() Poco::Int64 result = _redis.execute(sadd); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2528,7 +2573,7 @@ void RedisTest::testSUNIONSTORE() Poco::Int64 result = _redis.execute(sunionstore); assert(result == 5); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2539,12 +2584,13 @@ void RedisTest::testSUNIONSTORE() Array result = _redis.execute(smembers); assert(result.size() == 5); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testRENAME() { if (!_connected) @@ -2559,7 +2605,7 @@ void RedisTest::testRENAME() std::string result = _redis.execute(set); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2570,7 +2616,7 @@ void RedisTest::testRENAME() std::string result = _redis.execute(rename); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2581,12 +2627,13 @@ void RedisTest::testRENAME() BulkString result = _redis.execute(get); assert(result.value().compare("Hello") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testRENAMENX() { if (!_connected) @@ -2601,7 +2648,7 @@ void RedisTest::testRENAMENX() std::string result = _redis.execute(set); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2612,7 +2659,7 @@ void RedisTest::testRENAMENX() std::string result = _redis.execute(set); assert(result.compare("OK") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2623,7 +2670,7 @@ void RedisTest::testRENAMENX() Poco::Int64 result = _redis.execute(rename); assert(result == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2634,12 +2681,13 @@ void RedisTest::testRENAMENX() BulkString result = _redis.execute(get); assert(result.value().compare("World") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } } + void RedisTest::testRPOP() { if (!_connected) @@ -2665,7 +2713,7 @@ void RedisTest::testRPOP() result = _redis.execute(rpush); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2676,7 +2724,7 @@ void RedisTest::testRPOP() BulkString result = _redis.execute(rpop); assert(result.value().compare("three") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2690,17 +2738,18 @@ void RedisTest::testRPOP() assert(result.get(0).value().compare("one") == 0); assert(result.get(1).value().compare("two") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::NullValueException &e) + catch (Poco::NullValueException& e) { fail(e.message()); } } + void RedisTest::testRPOPLPUSH() { if (!_connected) @@ -2718,11 +2767,11 @@ void RedisTest::testRPOPLPUSH() { _redis.execute(delCommand); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } @@ -2741,7 +2790,7 @@ void RedisTest::testRPOPLPUSH() result = _redis.execute(rpush); assert(result == 3); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2752,7 +2801,7 @@ void RedisTest::testRPOPLPUSH() BulkString result = _redis.execute(rpoplpush); assert(result.value().compare("three") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2766,11 +2815,11 @@ void RedisTest::testRPOPLPUSH() assert(result.get(0).value().compare("one") == 0); assert(result.get(1).value().compare("two") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::NullValueException &e) + catch (Poco::NullValueException& e) { fail(e.message()); } @@ -2783,16 +2832,17 @@ void RedisTest::testRPOPLPUSH() assert(result.size() == 1); assert(result.get(0).value().compare("three") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::NullValueException &e) + catch (Poco::NullValueException& e) { fail(e.message()); } } + void RedisTest::testRPUSH() { if (!_connected) @@ -2814,7 +2864,7 @@ void RedisTest::testRPUSH() result = _redis.execute(rpush); assert(result == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } @@ -2825,11 +2875,11 @@ void RedisTest::testRPUSH() Poco::Int64 n = _redis.execute(llen); assert(n == 2); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } @@ -2843,16 +2893,17 @@ void RedisTest::testRPUSH() assert(result.get(0).value().compare("World") == 0); assert(result.get(1).value().compare("Hello") == 0); } - catch(RedisException &e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::NullValueException &e) + catch (Poco::NullValueException& e) { fail(e.message()); } } + void RedisTest::testPool() { Poco::Net::SocketAddress sa(_host, _port); @@ -2875,6 +2926,7 @@ void RedisTest::testPool() assert(keyValue.value().compare("Hello") == 0); } + void RedisTest::delKey(const std::string& key) { Command delCommand = Command::del(key); @@ -2882,11 +2934,11 @@ void RedisTest::delKey(const std::string& key) { _redis.execute(delCommand); } - catch(RedisException& e) + catch (RedisException& e) { fail(e.message()); } - catch(Poco::BadCastException& e) + catch (Poco::BadCastException& e) { fail(e.message()); } @@ -2951,7 +3003,6 @@ CppUnit::Test* RedisTest::suite() CppUnit_addTest(pSuite, RedisTest, testRPOP); CppUnit_addTest(pSuite, RedisTest, testRPOPLPUSH); CppUnit_addTest(pSuite, RedisTest, testRPUSH); - CppUnit_addTest(pSuite, RedisTest, testPool); return pSuite; diff --git a/Redis/testsuite/src/RedisTest.h b/Redis/testsuite/src/RedisTest.h index 9fb9bb9a2..b1c1bc75d 100644 --- a/Redis/testsuite/src/RedisTest.h +++ b/Redis/testsuite/src/RedisTest.h @@ -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" diff --git a/Redis/testsuite/src/RedisTestSuite.cpp b/Redis/testsuite/src/RedisTestSuite.cpp index f2e806a73..f3fea9c3f 100644 --- a/Redis/testsuite/src/RedisTestSuite.cpp +++ b/Redis/testsuite/src/RedisTestSuite.cpp @@ -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 diff --git a/Redis/testsuite/src/RedisTestSuite.h b/Redis/testsuite/src/RedisTestSuite.h index d8919cd8d..2c957fa1d 100644 --- a/Redis/testsuite/src/RedisTestSuite.h +++ b/Redis/testsuite/src/RedisTestSuite.h @@ -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 diff --git a/Redis/testsuite/src/WinCEDriver.cpp b/Redis/testsuite/src/WinCEDriver.cpp index 7f98d56fa..4243f706a 100644 --- a/Redis/testsuite/src/WinCEDriver.cpp +++ b/Redis/testsuite/src/WinCEDriver.cpp @@ -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 diff --git a/Redis/testsuite/src/WinDriver.cpp b/Redis/testsuite/src/WinDriver.cpp index f1d37cd3a..7b3adb48b 100644 --- a/Redis/testsuite/src/WinDriver.cpp +++ b/Redis/testsuite/src/WinDriver.cpp @@ -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