style and documentation fixes

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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