From: Date: Mon, 5 May 2008 03:32:10 +0000 (-0400) Subject: Merge 477:75823cad36b7 with -r 476 X-Git-Tag: 0.20~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=1d7f999b7d38db3308a0533a83fea23987fb0178;p=awesomized%2Flibmemcached Merge 477:75823cad36b7 with -r 476 --- 1d7f999b7d38db3308a0533a83fea23987fb0178 diff --cc libmemcached/memcached.hh index 00000000,f7e349e7..3bbcaf0b mode 000000,100644..100644 --- a/libmemcached/memcached.hh +++ b/libmemcached/memcached.hh @@@ -1,0 -1,100 +1,183 @@@ + #ifdef USE_PRAGMA_INTERFACE + #pragma interface /* gcc class implementation */ + #endif + + #include + #include + #include + + class Memcached + { + memcached_st memc; ++ memcached_result_st result; + + public: + + Memcached() + { + memcached_create(&memc); + } + + Memcached(memcached_st *clone) + { + memcached_clone(&memc, clone); + } ++ char *fetch (char *key, size_t *key_length, size_t *value_length) ++ { ++ uint32_t flags; ++ memcached_return rc; + ++ return memcached_fetch(&memc, key, key_length, ++ value_length, &flags, &rc); ++ } + char *get(char *key, size_t *value_length) + { + uint32_t flags; + memcached_return rc; + + return memcached_get(&memc, key, strlen(key), + value_length, &flags, &rc); + } + + char *get_by_key(char *master_key, char *key, size_t *value_length) + { + uint32_t flags; + memcached_return rc; + + return memcached_get_by_key(&memc, master_key, strlen(master_key), key, strlen(key), + value_length, &flags, &rc); + } + + memcached_return mget(char **keys, size_t *key_length, unsigned int number_of_keys) + { + + return memcached_mget(&memc, keys, key_length, number_of_keys); + } + + memcached_return set(char *key, char *value, size_t value_length) + { + return memcached_set(&memc, key, strlen(key), + value, value_length, + (time_t)0, (uint32_t)0); + } + + memcached_return set_by_key(char *master_key, char *key, char *value, size_t value_length) + { + return memcached_set_by_key(&memc, master_key, strlen(master_key), + key, strlen(key), + value, value_length, + (time_t)0, + (uint32_t)0 ); + } ++ memcached_return ++ increment(char *key, unsigned int offset, uint64_t *value) ++ { ++ return memcached_increment(&memc, key, strlen(key), ++ offset, value); ++ } ++ memcached_return ++ decrement(char *key, unsigned int offset, uint64_t *value) ++ { ++ return memcached_decrement(&memc, key, strlen(key), ++ offset, value); ++ } + + + memcached_return add(char *key, char *value, size_t value_length) + { + return memcached_add(&memc, key, strlen(key), + value, value_length, + (time_t)0, (uint32_t)0); + } ++ memcached_return add_by_key(char *master_key, char *key, char *value, size_t value_length) ++ { ++ return memcached_add_by_key(&memc, master_key, strlen(master_key), ++ key, strlen(key), ++ value, value_length, ++ (time_t)0, (uint32_t)0); ++ } + + memcached_return replace(char *key, char *value, size_t value_length) + { + return memcached_replace(&memc, key, strlen(key), + value, value_length, + (time_t)0, (uint32_t)0); + } ++ memcached_return replace_by_key(char *master_key, ++ char *key, char *value, size_t value_length) ++ { ++ return memcached_replace_by_key(&memc, master_key, strlen(master_key), ++ key, strlen(key), ++ value, value_length, ++ (time_t)0, (uint32_t)0); ++ } + + memcached_return prepend(char *key, char *value, size_t value_length) + { + return memcached_prepend(&memc, key, strlen(key), + value, value_length, + (time_t)0, + (uint32_t)0); + } - ++ memcached_return prepend_by_key(char *master_key, ++ char *key, char *value, size_t value_length) ++ { ++ return memcached_prepend_by_key(&memc, master_key, strlen(master_key), ++ key, strlen(key), ++ value, value_length, ++ (time_t)0, ++ (uint32_t)0); ++ } + + memcached_return append(char *key, char *value, size_t value_length) + { + return memcached_append(&memc, key, strlen(key), + value, value_length, + (time_t)0, + (uint32_t)0); + } ++ memcached_return append_by_key(char *master_key, ++ char *key, char *value, size_t value_length) ++ { ++ return memcached_append_by_key(&memc, ++ master_key, strlen(master_key), ++ key, strlen(key), ++ value, value_length, ++ (time_t)0, ++ (uint32_t)0); ++ } ++ memcached_return cas(char *key, char *value, size_t value_length, uint64_t cas) ++ { ++ return memcached_cas(&memc, key, strlen(key), ++ value, value_length, ++ (time_t)0, ++ (uint32_t)0, ++ cas); ++ } ++ memcached_return cas_by_key(char *master_key, char *key, char *value, ++ size_t value_length, uint64_t cas) ++ { ++ return memcached_cas_by_key(&memc, ++ master_key, strlen(master_key), ++ key, strlen(key), ++ value, value_length, ++ (time_t)0, ++ (uint32_t)0, ++ cas); ++ } ++ // using 'remove' vs. 'delete' since 'delete' is a keyword ++ memcached_return remove(char *key) ++ { ++ return memcached_delete (&memc, key, strlen(key), (time_t)0); ++ ++ } ++ memcached_return delete_by_key(char *master_key, char *key) ++ { ++ return memcached_delete_by_key(&memc, master_key, strlen(master_key), ++ key, strlen(key), (time_t)0); ++ } + ~Memcached() + { + memcached_free(&memc); + } + }; diff --cc tests/plus.cpp index 2e5ea513,20a537b1..ab9cdbe6 --- a/tests/plus.cpp +++ b/tests/plus.cpp @@@ -27,42 -27,10 +27,43 @@@ test_return basic_test(memcached_st *me assert((memcmp(value, value_set, value_length) == 0)); - return 0; + return TEST_SUCCESS; } + +uint8_t increment_test(memcached_st *memc) +{ + Memcached mcach; + memcached_return rc; + char *key= "inctest"; + char *inc_value= "1"; + char *ret_value; + uint64_t int_inc_value; + uint64_t int_ret_value; + size_t value_length; + + mcach.set(key, inc_value, strlen(inc_value)); + ret_value= mcach.get(key, &value_length); + printf("\nretvalue %s\n",ret_value); + int_inc_value= atoi(inc_value); + int_ret_value= atoi(ret_value); + assert(int_ret_value == int_inc_value); + + rc= mcach.increment(key, 1, &int_ret_value); + assert(rc == MEMCACHED_SUCCESS); + assert(int_ret_value == 2); + + rc= mcach.increment(key, 1, &int_ret_value); + assert(rc == MEMCACHED_SUCCESS); + assert(int_ret_value == 3); + + rc= mcach.increment(key, 5, &int_ret_value); + assert(rc == MEMCACHED_SUCCESS); + assert(int_ret_value == 8); + + return 0; +} + - uint8_t basic_master_key_test(memcached_st *memc) + test_return basic_master_key_test(memcached_st *memc) { Memcached foo; char *value_set= "Data for server A";