mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-31 22:45:36 +01:00
Use Poco::Nullable instead of Poco::Optional for BulkString
This commit is contained in:
parent
f9af763cf6
commit
40f20421a8
@ -38,18 +38,17 @@ class Redis_API Client
|
||||
/// bit integer, a simple string, a bulk string, an array or an error. The
|
||||
/// first element of the command array is the Redis command. A simple string
|
||||
/// is a string that cannot contain a CR or LF character. A bulk string is
|
||||
/// implemented as a typedef for Poco::Optional<std::string>. This is
|
||||
/// because a bulk string can represent a Null value. When the optional
|
||||
/// object isn't assigned, you know that a Null value is returned:
|
||||
/// implemented as a typedef for Poco::Nullable<std::string>. This is
|
||||
/// because a bulk string can represent a Null value.
|
||||
///
|
||||
/// BulkString bs = client.sendCommand(...);
|
||||
/// if ( bs.isSpecified() )
|
||||
/// if ( bs.isNull() )
|
||||
/// {
|
||||
/// // We have a std::string
|
||||
/// // We have a Null value
|
||||
/// }
|
||||
/// else
|
||||
/// {
|
||||
/// // We have a Null value
|
||||
/// // We have a string value
|
||||
/// }
|
||||
{
|
||||
public:
|
||||
@ -92,9 +91,9 @@ public:
|
||||
/// Sends a Redis command to the server and returns the reply
|
||||
|
||||
template<typename T>
|
||||
void sendCommand(const Array& command, T& result)
|
||||
void sendCommand(const Array& command, T& result)
|
||||
/// Sends a Redis command to the server, gets the reply and tries
|
||||
/// to convert that reply to the template type. When
|
||||
/// to convert that reply to the template type. When
|
||||
/// the reply is a Redis error, it wil throw a RedisException.
|
||||
/// A BadCastException will be thrown, when the reply is not of the
|
||||
/// given type.
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Optional.h"
|
||||
#include "Poco/Nullable.h"
|
||||
|
||||
#include "Poco/Redis/Redis.h"
|
||||
#include "Poco/Redis/RedisSocket.h"
|
||||
@ -92,7 +92,9 @@ struct ElementTraits<std::string>
|
||||
};
|
||||
|
||||
|
||||
typedef Optional<std::string> BulkString;
|
||||
typedef Nullable<std::string> BulkString;
|
||||
/// A bulk string is a string that can contain a NULL value.
|
||||
/// So, BulkString is a typedef for Nullable<std::string>.
|
||||
|
||||
|
||||
template<>
|
||||
@ -104,12 +106,19 @@ struct ElementTraits<BulkString>
|
||||
|
||||
static std::string toString(const BulkString& value)
|
||||
{
|
||||
if ( value.isSpecified() )
|
||||
if ( value.isNull() )
|
||||
{
|
||||
return marker + std::string("-1") + LineEnding::NEWLINE_CRLF;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string s = value.value();
|
||||
return marker + NumberFormatter::format(s.length()) + LineEnding::NEWLINE_CRLF + s + LineEnding::NEWLINE_CRLF;
|
||||
return marker
|
||||
+ NumberFormatter::format(s.length())
|
||||
+ LineEnding::NEWLINE_CRLF
|
||||
+ s
|
||||
+ LineEnding::NEWLINE_CRLF;
|
||||
}
|
||||
return marker + std::string("-1") + LineEnding::NEWLINE_CRLF;
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user