Permalink
Browse files

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

…ncrement and decrement.
  • Loading branch information...
1 parent 02d5cf4 commit 31e4ec4da3a1454048854fc5935da6cd071dea82 @mikhailberis committed Dec 12, 2009
Showing with 40 additions and 4 deletions.
  1. +21 −2 memcachepp/memcache/fluent/key.hpp
  2. +19 −2 test/memcache_fluent_interface.cpp
@@ -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
@@ -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()

0 comments on commit 31e4ec4

Please sign in to comment.