X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fcpp_example.cc;h=b96aaf4e1c23bf7a838f5f7904dc619e3dbe65f2;hb=b30880274b5b866db3780148eaf9bf36e09bb1fb;hp=6feb26ab5e0b00baa3e7f25bfe8447dc0323e6fb;hpb=a715683d855fd0ee03d9557abb3c3f739e61a354;p=awesomized%2Flibmemcached diff --git a/tests/cpp_example.cc b/tests/cpp_example.cc index 6feb26ab..b96aaf4e 100644 --- a/tests/cpp_example.cc +++ b/tests/cpp_example.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -13,6 +14,16 @@ using namespace std; using namespace memcache; +class DeletePtrs +{ +public: + template + inline void operator()(const T *ptr) const + { + delete ptr; + } +}; + class MyCache { public: @@ -47,9 +58,12 @@ public: Memcache *getCache() { - /* pick a random element from the vector of clients */ - Memcache *first= clients[0]; - return first; + /* + * pick a random element from the vector of clients. Obviously, this is + * not very random but suffices as an example! + */ + uint32_t index= rand() % num_of_clients; + return clients[index]; } private: @@ -73,6 +87,7 @@ private: ~MyCache() { + for_each(clients.begin(), clients.end(), DeletePtrs()); clients.clear(); } @@ -152,6 +167,7 @@ void setProduct(const string &key, const Product &product) int main() { +#if 0 Product pad(1, 5.0); const string key("padraig"); cout << "Going to set an object in the cache..." << endl; @@ -175,5 +191,12 @@ int main() cout << "product " << (*iter).getId() << " costs " << (*iter).getPrice() << endl; ++iter; } +#endif + Memcache first_client("127.0.0.1:11211"); + Memcache second_client("127.0.0.1", 11211); + //first_client.set("key", some_vector_of_chars, expiry, flags); + //first_client.get("key", vector_to_fill_with_data); + //first_client.remove("key"); + first_client.addServer("192.168.1.1", 11211); return 0; }