Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changing the interface for append and prepend, implementing unitary i…

…ncrement and decrement.
  • Loading branch information...
commit 31e4ec4da3a1454048854fc5935da6cd071dea82 1 parent 02d5cf4
@mikhailberis authored
View
23 memcachepp/memcache/fluent/key.hpp
@@ -136,24 +136,43 @@ namespace memcache {
}
key_impl const &
- operator +=(string const & data) const {
+ operator >>=(string const & data) const {
handle_ <<
::memcache::raw_append(key_, data, expiration_, failover_expiration_);
return *this;
}
key_impl const &
- operator -=(string const & data) const {
+ operator <<=(string const & data) const {
handle_ <<
::memcache::raw_prepend(key_, data, expiration_, failover_expiration_);
return *this;
}
+
+ key_impl const &
+ operator ++(int) const {
+ handle_ <<
+ ::memcache::incr(key_, value_, 1u);
+ return *this;
+ }
+
+ key_impl const &
+ operator --(int) const {
+ handle_ <<
+ ::memcache::decr(key_, value_, 1u);
+ return *this;
+ }
+
+ operator boost::uint64_t const & () const {
+ return value_;
+ }
private:
Handle & handle_;
mutable std::string key_;
mutable detail::expire_type expiration_;
mutable detail::failover_expire_type failover_expiration_;
+ mutable boost::uint64_t value_;
};
}; // namespace fluent
View
21 test/memcache_fluent_interface.cpp
@@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE ( key_raw_append_test ) {
BOOST_CHECK_NO_THROW ( key(mc, "hello") *= "Hello" );
BOOST_CHECK_NO_THROW ( wrap(container) = raw(mc, "hello") );
BOOST_CHECK_EQUAL ( std::string("Hello"), container );
- BOOST_CHECK_NO_THROW ( key(mc, "hello") += " World!" );
+ BOOST_CHECK_NO_THROW ( key(mc, "hello") >>= " World!" );
BOOST_CHECK_NO_THROW ( wrap(container) = raw(mc, "hello") );
BOOST_CHECK_EQUAL ( std::string("Hello World!"), container );
}
@@ -109,10 +109,27 @@ BOOST_AUTO_TEST_CASE ( key_raw_prepend_test ) {
BOOST_CHECK_NO_THROW ( key(mc, "hello") *= "World!" );
BOOST_CHECK_NO_THROW ( wrap(container) = raw(mc, "hello") );
BOOST_CHECK_EQUAL ( std::string("World!"), container );
- BOOST_CHECK_NO_THROW ( key(mc, "hello") -= "Hello " );
+ BOOST_CHECK_NO_THROW ( key(mc, "hello") <<= "Hello " );
BOOST_CHECK_NO_THROW ( wrap(container) = raw(mc, "hello") );
BOOST_CHECK_EQUAL ( std::string("Hello World!"), container );
}
+BOOST_AUTO_TEST_CASE ( key_increment_decrement_test ) {
+ // We want to support incrementing and decrementing raw-set keys.
+ using namespace memcache::fluent;
+ boost::uint64_t value = 0u;
+ BOOST_CHECK_NO_THROW ( key(mc, "hello") *= "0" );
+ BOOST_CHECK_NO_THROW ( wrap(container) = raw(mc, "hello") );
+ BOOST_CHECK_EQUAL ( std::string("0"), container );
+ BOOST_CHECK_NO_THROW ( value = key(mc, "hello")++ );
+ BOOST_CHECK_NO_THROW ( wrap(container) = raw(mc, "hello") );
+ BOOST_CHECK_EQUAL ( std::string("1"), container );
+ BOOST_CHECK_EQUAL ( 1u, value );
+ BOOST_CHECK_NO_THROW ( value = key(mc, "hello")-- );
+ BOOST_CHECK_NO_THROW ( wrap(container) = raw(mc, "hello") );
+ BOOST_CHECK_EQUAL ( std::string("0"), container );
+ BOOST_CHECK_EQUAL ( 0u, value );
+}
+
BOOST_AUTO_TEST_SUITE_END()
Please sign in to comment.
Something went wrong with that request. Please try again.