| memcached.hpp | | memcached.hpp | |
| | | | |
| skipping to change at line 19 | | skipping to change at line 19 | |
| | | | |
| /** | | /** | |
| * @file memcached.hpp | | * @file memcached.hpp | |
| * @brief Libmemcached C++ interface | | * @brief Libmemcached C++ interface | |
| */ | | */ | |
| | | | |
| #ifndef LIBMEMCACHEDPP_H | | #ifndef LIBMEMCACHEDPP_H | |
| #define LIBMEMCACHEDPP_H | | #define LIBMEMCACHEDPP_H | |
| | | | |
| #include <libmemcached/memcached.h> | | #include <libmemcached/memcached.h> | |
|
| | | #include <libmemcached/exception.hpp> | |
| | | | |
| #include <string.h> | | #include <string.h> | |
| | | | |
|
| | | #include <sstream> | |
| #include <string> | | #include <string> | |
| #include <vector> | | #include <vector> | |
| #include <map> | | #include <map> | |
| | | | |
| namespace memcache | | namespace memcache | |
| { | | { | |
| | | | |
| /** | | /** | |
| * This is the core memcached library (if later, other objects | | * This is the core memcached library (if later, other objects | |
| * are needed, they will be created from this class). | | * are needed, they will be created from this class). | |
| */ | | */ | |
| class Memcache | | class Memcache | |
| { | | { | |
| public: | | public: | |
| | | | |
| Memcache() | | Memcache() | |
| : | | : | |
|
| | | servers_list(), | |
| memc(), | | memc(), | |
|
| | | servers(NULL), | |
| result() | | result() | |
| { | | { | |
| memcached_create(&memc); | | memcached_create(&memc); | |
| } | | } | |
| | | | |
|
| | | Memcache(const std::string &in_servers_list) | |
| | | : | |
| | | servers_list(in_servers_list), | |
| | | memc(), | |
| | | servers(NULL), | |
| | | result() | |
| | | { | |
| | | memcached_create(&memc); | |
| | | servers= memcached_servers_parse(servers_list.c_str()); | |
| | | memcached_server_push(&memc, servers); | |
| | | } | |
| | | | |
| | | Memcache(const std::string &hostname, | |
| | | unsigned int port) | |
| | | : | |
| | | servers_list(), | |
| | | memc(), | |
| | | servers(NULL), | |
| | | result() | |
| | | { | |
| | | memcached_create(&memc); | |
| | | servers_list.append(hostname); | |
| | | servers_list.append(":"); | |
| | | std::ostringstream strsmt; | |
| | | strsmt << port; | |
| | | servers_list.append(strsmt.str()); | |
| | | servers= memcached_servers_parse(servers_list.c_str()); | |
| | | memcached_server_push(&memc, servers); | |
| | | } | |
| | | | |
| Memcache(memcached_st *clone) | | Memcache(memcached_st *clone) | |
| : | | : | |
|
| | | servers_list(), | |
| memc(), | | memc(), | |
|
| | | servers(NULL), | |
| result() | | result() | |
| { | | { | |
| memcached_clone(&memc, clone); | | memcached_clone(&memc, clone); | |
| } | | } | |
| | | | |
| Memcache(const Memcache &rhs) | | Memcache(const Memcache &rhs) | |
| : | | : | |
|
| | | servers_list(rhs.servers_list), | |
| memc(), | | memc(), | |
|
| | | servers(NULL), | |
| result() | | result() | |
| { | | { | |
| memcached_clone(&memc, const_cast<memcached_st *>(&rhs.getImpl())); | | memcached_clone(&memc, const_cast<memcached_st *>(&rhs.getImpl())); | |
|
| | | servers= memcached_servers_parse(servers_list.c_str()); | |
| | | memcached_server_push(&memc, servers); | |
| | | } | |
| | | | |
| | | Memcache &operator=(const Memcache &rhs) | |
| | | { | |
| | | if (this != &rhs) | |
| | | { | |
| | | memcached_clone(&memc, const_cast<memcached_st *>(&rhs.getImpl())); | |
| | | servers= memcached_servers_parse(servers_list.c_str()); | |
| | | memcached_server_push(&memc, servers); | |
| | | } | |
| | | return *this; | |
| } | | } | |
| | | | |
| ~Memcache() | | ~Memcache() | |
| { | | { | |
| memcached_free(&memc); | | memcached_free(&memc); | |
|
| | | memcached_server_list_free(servers); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Get the internal memcached_st * | | * Get the internal memcached_st * | |
| */ | | */ | |
| memcached_st &getImpl() | | memcached_st &getImpl() | |
| { | | { | |
| return memc; | | return memc; | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 95 | | skipping to change at line 147 | |
| * @param[in] rc a memcached_return structure | | * @param[in] rc a memcached_return structure | |
| * @return error string corresponding to given return code in the library
. | | * @return error string corresponding to given return code in the library
. | |
| */ | | */ | |
| const std::string getError(memcached_return rc) const | | const std::string getError(memcached_return rc) const | |
| { | | { | |
| /* first parameter to strerror is unused */ | | /* first parameter to strerror is unused */ | |
| return memcached_strerror(NULL, rc); | | return memcached_strerror(NULL, rc); | |
| } | | } | |
| | | | |
| /** | | /** | |
|
| | | * Return the string which contains the list of memcached servers being | |
| | | * used. | |
| | | * | |
| | | * @return a std::string containing the list of memcached servers | |
| | | */ | |
| | | const std::string getServersList() const | |
| | | { | |
| | | return servers_list; | |
| | | } | |
| | | | |
| | | /** | |
| | | * Set the list of memcached servers to use. | |
| | | * | |
| | | * @param[in] in_servers_list list of servers | |
| | | * @return true on success; false otherwise | |
| | | */ | |
| | | bool setServers(const std::string &in_servers_list) | |
| | | { | |
| | | servers_list.assign(in_servers_list); | |
| | | servers= memcached_servers_parse(in_servers_list.c_str()); | |
| | | return (servers == NULL); | |
| | | } | |
| | | | |
| | | /** | |
| | | * Add a server to the list of memcached servers to use. | |
| | | * | |
| | | * @param[in] server_name name of the server to add | |
| | | * @param[in[ port port number of server to add | |
| | | * @return true on success; false otherwise | |
| | | */ | |
| | | bool addServer(const std::string &server_name, unsigned int port) | |
| | | { | |
| | | memcached_return rc; | |
| | | std::ostringstream strstm; | |
| | | servers_list.append(","); | |
| | | servers_list.append(server_name); | |
| | | servers_list.append(":"); | |
| | | strstm << port; | |
| | | servers_list.append(strstm.str()); | |
| | | servers= memcached_server_list_append(servers, | |
| | | server_name.c_str(), | |
| | | port, | |
| | | &rc); | |
| | | return (rc == MEMCACHED_SUCCESS); | |
| | | } | |
| | | | |
| | | /** | |
| * Fetches an individual value from the server. mget() must always | | * Fetches an individual value from the server. mget() must always | |
| * be called before using this method. | | * be called before using this method. | |
| * | | * | |
| * @param[in] key key of object to fetch | | * @param[in] key key of object to fetch | |
| * @param[out] ret_val store returned object in this vector | | * @param[out] ret_val store returned object in this vector | |
| * @return a memcached return structure | | * @return a memcached return structure | |
| */ | | */ | |
| memcached_return fetch(std::string &key, | | memcached_return fetch(std::string &key, | |
| std::vector<char> &ret_val) | | std::vector<char> &ret_val) | |
| { | | { | |
| | | | |
| skipping to change at line 130 | | skipping to change at line 229 | |
| | | | |
| /** | | /** | |
| * Fetches an individual value from the server. | | * Fetches an individual value from the server. | |
| * | | * | |
| * @param[in] key key of object whose value to get | | * @param[in] key key of object whose value to get | |
| * @param[out] ret_val object that is retrieved is stored in | | * @param[out] ret_val object that is retrieved is stored in | |
| * this vector | | * this vector | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool get(const std::string &key, | | bool get(const std::string &key, | |
|
| std::vector<char> &ret_val) | | std::vector<char> &ret_val) throw (Error) | |
| { | | { | |
| uint32_t flags= 0; | | uint32_t flags= 0; | |
| memcached_return rc; | | memcached_return rc; | |
| size_t value_length= 0; | | size_t value_length= 0; | |
| | | | |
| if (key.empty()) | | if (key.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the key supplied is empty!", false)); | |
| } | | } | |
| char *value= memcached_get(&memc, key.c_str(), key.length(), | | char *value= memcached_get(&memc, key.c_str(), key.length(), | |
| &value_length, &flags, &rc); | | &value_length, &flags, &rc); | |
| if (value != NULL && ret_val.empty()) | | if (value != NULL && ret_val.empty()) | |
| { | | { | |
| ret_val.reserve(value_length); | | ret_val.reserve(value_length); | |
| ret_val.assign(value, value + value_length); | | ret_val.assign(value, value + value_length); | |
| return true; | | return true; | |
| } | | } | |
| return false; | | return false; | |
| | | | |
| skipping to change at line 165 | | skipping to change at line 264 | |
| * used for storage. | | * used for storage. | |
| * | | * | |
| * @param[in] master_key key that specifies server object is stored on | | * @param[in] master_key key that specifies server object is stored on | |
| * @param[in] key key of object whose value to get | | * @param[in] key key of object whose value to get | |
| * @param[out] ret_val object that is retrieved is stored in | | * @param[out] ret_val object that is retrieved is stored in | |
| * this vector | | * this vector | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool getByKey(const std::string &master_key, | | bool getByKey(const std::string &master_key, | |
| const std::string &key, | | const std::string &key, | |
|
| std::vector<char> &ret_val) | | std::vector<char> &ret_val) throw(Error) | |
| { | | { | |
| uint32_t flags= 0; | | uint32_t flags= 0; | |
| memcached_return rc; | | memcached_return rc; | |
| size_t value_length= 0; | | size_t value_length= 0; | |
| | | | |
| if (master_key.empty() || key.empty()) | | if (master_key.empty() || key.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the master key or key supplied is empty!", false)); | |
| } | | } | |
| char *value= memcached_get_by_key(&memc, | | char *value= memcached_get_by_key(&memc, | |
| master_key.c_str(), master_key.length
(), | | master_key.c_str(), master_key.length
(), | |
| key.c_str(), key.length(), | | key.c_str(), key.length(), | |
| &value_length, &flags, &rc); | | &value_length, &flags, &rc); | |
| if (value) | | if (value) | |
| { | | { | |
| ret_val.reserve(value_length); | | ret_val.reserve(value_length); | |
| ret_val.assign(value, value + value_length); | | ret_val.assign(value, value + value_length); | |
| return true; | | return true; | |
| | | | |
| skipping to change at line 245 | | skipping to change at line 344 | |
| * | | * | |
| * @param[in] key key of object to write to server | | * @param[in] key key of object to write to server | |
| * @param[in] value value of object to write to server | | * @param[in] value value of object to write to server | |
| * @param[in] expiration time to keep the object stored in the server for | | * @param[in] expiration time to keep the object stored in the server for | |
| * @param[in] flags flags to store with the object | | * @param[in] flags flags to store with the object | |
| * @return true on succcess; false otherwise | | * @return true on succcess; false otherwise | |
| */ | | */ | |
| bool set(const std::string &key, | | bool set(const std::string &key, | |
| const std::vector<char> &value, | | const std::vector<char> &value, | |
| time_t expiration, | | time_t expiration, | |
|
| uint32_t flags) | | uint32_t flags) throw(Error) | |
| { | | { | |
| if (key.empty() || value.empty()) | | if (key.empty() || value.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the key or value supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_set(&memc, | | memcached_return rc= memcached_set(&memc, | |
| key.c_str(), key.length(), | | key.c_str(), key.length(), | |
| &value[0], value.size(), | | &value[0], value.size(), | |
| expiration, flags); | | expiration, flags); | |
| return (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); | | return (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Writes an object to a server specified by the master_key parameter. | | * Writes an object to a server specified by the master_key parameter. | |
| | | | |
| skipping to change at line 273 | | skipping to change at line 372 | |
| * @param[in] key key of object to write to server | | * @param[in] key key of object to write to server | |
| * @param[in] value value of object to write to server | | * @param[in] value value of object to write to server | |
| * @param[in] expiration time to keep the object stored in the server for | | * @param[in] expiration time to keep the object stored in the server for | |
| * @param[in] flags flags to store with the object | | * @param[in] flags flags to store with the object | |
| * @return true on succcess; false otherwise | | * @return true on succcess; false otherwise | |
| */ | | */ | |
| bool setByKey(const std::string &master_key, | | bool setByKey(const std::string &master_key, | |
| const std::string &key, | | const std::string &key, | |
| const std::vector<char> &value, | | const std::vector<char> &value, | |
| time_t expiration, | | time_t expiration, | |
|
| uint32_t flags) | | uint32_t flags) throw(Error) | |
| { | | { | |
| if (master_key.empty() || | | if (master_key.empty() || | |
| key.empty() || | | key.empty() || | |
| value.empty()) | | value.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the key or value supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_set_by_key(&memc, master_key.c_str(), | | memcached_return rc= memcached_set_by_key(&memc, master_key.c_str(), | |
| master_key.length(), | | master_key.length(), | |
| key.c_str(), key.length(), | | key.c_str(), key.length(), | |
| &value[0], value.size(), | | &value[0], value.size(), | |
| expiration, | | expiration, | |
| flags); | | flags); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 303 | | skipping to change at line 402 | |
| * | | * | |
| * @param[in] keys vector of keys of objects to write to server | | * @param[in] keys vector of keys of objects to write to server | |
| * @param[in] values vector of values of objects to write to server | | * @param[in] values vector of values of objects to write to server | |
| * @param[in] expiration time to keep the objects stored in server for | | * @param[in] expiration time to keep the objects stored in server for | |
| * @param[in] flags flags to store with the objects | | * @param[in] flags flags to store with the objects | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool setAll(std::vector<std::string> &keys, | | bool setAll(std::vector<std::string> &keys, | |
| std::vector< std::vector<char> *> &values, | | std::vector< std::vector<char> *> &values, | |
| time_t expiration, | | time_t expiration, | |
|
| uint32_t flags) | | uint32_t flags) throw(Error) | |
| { | | { | |
| if (keys.size() != values.size()) | | if (keys.size() != values.size()) | |
| { | | { | |
|
| return false; | | throw(Error("The number of keys and values do not match!", false)); | |
| } | | } | |
| bool retval= true; | | bool retval= true; | |
| std::vector<std::string>::iterator key_it= keys.begin(); | | std::vector<std::string>::iterator key_it= keys.begin(); | |
| std::vector< std::vector<char> *>::iterator val_it= values.begin(); | | std::vector< std::vector<char> *>::iterator val_it= values.begin(); | |
| while (key_it != keys.end()) | | while (key_it != keys.end()) | |
| { | | { | |
| retval= set((*key_it), *(*val_it), expiration, flags); | | retval= set((*key_it), *(*val_it), expiration, flags); | |
| if (retval == false) | | if (retval == false) | |
| { | | { | |
| return retval; | | return retval; | |
| | | | |
| skipping to change at line 336 | | skipping to change at line 435 | |
| * Writes a list of objects to the server. Objects are specified by | | * Writes a list of objects to the server. Objects are specified by | |
| * a map of keys to values. | | * a map of keys to values. | |
| * | | * | |
| * @param[in] key_value_map map of keys and values to store in server | | * @param[in] key_value_map map of keys and values to store in server | |
| * @param[in] expiration time to keep the objects stored in server for | | * @param[in] expiration time to keep the objects stored in server for | |
| * @param[in] flags flags to store with the objects | | * @param[in] flags flags to store with the objects | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool setAll(std::map<const std::string, std::vector<char> > &key_value_ma
p, | | bool setAll(std::map<const std::string, std::vector<char> > &key_value_ma
p, | |
| time_t expiration, | | time_t expiration, | |
|
| uint32_t flags) | | uint32_t flags) throw(Error) | |
| { | | { | |
| if (key_value_map.empty()) | | if (key_value_map.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("The key/values are not properly set!", false)); | |
| } | | } | |
| bool retval= true; | | bool retval= true; | |
| std::map<const std::string, std::vector<char> >::iterator it= | | std::map<const std::string, std::vector<char> >::iterator it= | |
| key_value_map.begin(); | | key_value_map.begin(); | |
| while (it != key_value_map.end()) | | while (it != key_value_map.end()) | |
| { | | { | |
| retval= set(it->first, it->second, expiration, flags); | | retval= set(it->first, it->second, expiration, flags); | |
| if (retval == false) | | if (retval == false) | |
| { | | { | |
|
| return false; | | std::string err_buff("There was an error setting the key "); | |
| | | err_buff.append(it->first); | |
| | | throw(Error(err_buff, false)); | |
| } | | } | |
| ++it; | | ++it; | |
| } | | } | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Increment the value of the object associated with the specified | | * Increment the value of the object associated with the specified | |
| * key by the offset given. The resulting value is saved in the value | | * key by the offset given. The resulting value is saved in the value | |
| * parameter. | | * parameter. | |
| * | | * | |
| * @param[in] key key of object in server whose value to increment | | * @param[in] key key of object in server whose value to increment | |
| * @param[in] offset amount to increment object's value by | | * @param[in] offset amount to increment object's value by | |
| * @param[out] value store the result of the increment here | | * @param[out] value store the result of the increment here | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
|
| bool increment(const std::string &key, uint32_t offset, uint64_t *value) | | bool increment(const std::string &key, uint32_t offset, uint64_t *value)
throw(Error) | |
| { | | { | |
| if (key.empty()) | | if (key.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the key supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_increment(&memc, key.c_str(), key.length
(), | | memcached_return rc= memcached_increment(&memc, key.c_str(), key.length
(), | |
| offset, value); | | offset, value); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Decrement the value of the object associated with the specified | | * Decrement the value of the object associated with the specified | |
| * key by the offset given. The resulting value is saved in the value | | * key by the offset given. The resulting value is saved in the value | |
| * parameter. | | * parameter. | |
| * | | * | |
| * @param[in] key key of object in server whose value to decrement | | * @param[in] key key of object in server whose value to decrement | |
| * @param[in] offset amount to increment object's value by | | * @param[in] offset amount to increment object's value by | |
| * @param[out] value store the result of the decrement here | | * @param[out] value store the result of the decrement here | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool decrement(const std::string &key, uint32_t offset, uint64_t *value) | | bool decrement(const std::string &key, uint32_t offset, uint64_t *value) | |
|
| | | throw(Error) | |
| { | | { | |
| if (key.empty()) | | if (key.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the key supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_decrement(&memc, key.c_str(), | | memcached_return rc= memcached_decrement(&memc, key.c_str(), | |
| key.length(), | | key.length(), | |
| offset, value); | | offset, value); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Add an object with the specified key and value to the server. This | | * Add an object with the specified key and value to the server. This | |
| * function returns false if the object already exists on the server. | | * function returns false if the object already exists on the server. | |
| * | | * | |
| * @param[in] key key of object to add | | * @param[in] key key of object to add | |
| * @param[in] value of object to add | | * @param[in] value of object to add | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool add(const std::string &key, const std::vector<char> &value) | | bool add(const std::string &key, const std::vector<char> &value) | |
|
| | | throw(Error) | |
| { | | { | |
| if (key.empty() || value.empty()) | | if (key.empty() || value.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the key or value supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_add(&memc, key.c_str(), key.length(), | | memcached_return rc= memcached_add(&memc, key.c_str(), key.length(), | |
| &value[0], value.size(), 0, 0); | | &value[0], value.size(), 0, 0); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Add an object with the specified key and value to the server. This | | * Add an object with the specified key and value to the server. This | |
| * function returns false if the object already exists on the server. The | | * function returns false if the object already exists on the server. The | |
| * server to add the object to is specified by the master_key parameter. | | * server to add the object to is specified by the master_key parameter. | |
| * | | * | |
| * @param[in[ master_key key of server to add object to | | * @param[in[ master_key key of server to add object to | |
| * @param[in] key key of object to add | | * @param[in] key key of object to add | |
| * @param[in] value of object to add | | * @param[in] value of object to add | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool addByKey(const std::string &master_key, | | bool addByKey(const std::string &master_key, | |
| const std::string &key, | | const std::string &key, | |
|
| const std::vector<char> &value) | | const std::vector<char> &value) throw(Error) | |
| { | | { | |
| if (master_key.empty() || | | if (master_key.empty() || | |
| key.empty() || | | key.empty() || | |
| value.empty()) | | value.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the master key or key supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_add_by_key(&memc, | | memcached_return rc= memcached_add_by_key(&memc, | |
| master_key.c_str(), | | master_key.c_str(), | |
| master_key.length(), | | master_key.length(), | |
| key.c_str(), | | key.c_str(), | |
| key.length(), | | key.length(), | |
| &value[0], | | &value[0], | |
| value.size(), | | value.size(), | |
| 0, 0); | | 0, 0); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Replaces an object on the server. This method only succeeds | | * Replaces an object on the server. This method only succeeds | |
| * if the object is already present on the server. | | * if the object is already present on the server. | |
| * | | * | |
| * @param[in] key key of object to replace | | * @param[in] key key of object to replace | |
| * @param[in[ value value to replace object with | | * @param[in[ value value to replace object with | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
|
| bool replace(const std::string &key, const std::vector<char> &value) | | bool replace(const std::string &key, const std::vector<char> &value) thro
w(Error) | |
| { | | { | |
| if (key.empty() || | | if (key.empty() || | |
| value.empty()) | | value.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the key or value supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_replace(&memc, key.c_str(), key.length()
, | | memcached_return rc= memcached_replace(&memc, key.c_str(), key.length()
, | |
| &value[0], value.size(), | | &value[0], value.size(), | |
| 0, 0); | | 0, 0); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Replaces an object on the server. This method only succeeds | | * Replaces an object on the server. This method only succeeds | |
| * if the object is already present on the server. The server | | * if the object is already present on the server. The server | |
| | | | |
| skipping to change at line 489 | | skipping to change at line 592 | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool replaceByKey(const std::string &master_key, | | bool replaceByKey(const std::string &master_key, | |
| const std::string &key, | | const std::string &key, | |
| const std::vector<char> &value) | | const std::vector<char> &value) | |
| { | | { | |
| if (master_key.empty() || | | if (master_key.empty() || | |
| key.empty() || | | key.empty() || | |
| value.empty()) | | value.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the master key or key supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_replace_by_key(&memc, | | memcached_return rc= memcached_replace_by_key(&memc, | |
| master_key.c_str(), | | master_key.c_str(), | |
| master_key.length(), | | master_key.length(), | |
| key.c_str(), | | key.c_str(), | |
| key.length(), | | key.length(), | |
| &value[0], | | &value[0], | |
| value.size(), | | value.size(), | |
| 0, 0); | | 0, 0); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Places a segment of data before the last piece of data stored. | | * Places a segment of data before the last piece of data stored. | |
| * | | * | |
| * @param[in] key key of object whose value we will prepend data to | | * @param[in] key key of object whose value we will prepend data to | |
| * @param[in] value data to prepend to object's value | | * @param[in] value data to prepend to object's value | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool prepend(const std::string &key, const std::vector<char> &value) | | bool prepend(const std::string &key, const std::vector<char> &value) | |
|
| | | throw(Error) | |
| { | | { | |
| if (key.empty() || value.empty()) | | if (key.empty() || value.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the key or value supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_prepend(&memc, key.c_str(), key.length()
, | | memcached_return rc= memcached_prepend(&memc, key.c_str(), key.length()
, | |
| &value[0], value.size(), 0, 0); | | &value[0], value.size(), 0, 0); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Places a segment of data before the last piece of data stored. The | | * Places a segment of data before the last piece of data stored. The | |
| * server on which the object where we will be prepending data is stored | | * server on which the object where we will be prepending data is stored | |
| * on is specified by the master_key parameter. | | * on is specified by the master_key parameter. | |
| * | | * | |
| * @param[in] master_key key of server where object is stored | | * @param[in] master_key key of server where object is stored | |
| * @param[in] key key of object whose value we will prepend data to | | * @param[in] key key of object whose value we will prepend data to | |
| * @param[in] value data to prepend to object's value | | * @param[in] value data to prepend to object's value | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool prependByKey(const std::string &master_key, | | bool prependByKey(const std::string &master_key, | |
| const std::string &key, | | const std::string &key, | |
| const std::vector<char> &value) | | const std::vector<char> &value) | |
|
| | | throw(Error) | |
| { | | { | |
| if (master_key.empty() || | | if (master_key.empty() || | |
| key.empty() || | | key.empty() || | |
| value.empty()) | | value.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the master key or key supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_prepend_by_key(&memc, | | memcached_return rc= memcached_prepend_by_key(&memc, | |
| master_key.c_str(), | | master_key.c_str(), | |
| master_key.length(), | | master_key.length(), | |
| key.c_str(), | | key.c_str(), | |
| key.length(), | | key.length(), | |
| &value[0], | | &value[0], | |
| value.size(), | | value.size(), | |
| 0, | | 0, | |
| 0); | | 0); | |
| | | | |
| skipping to change at line 560 | | skipping to change at line 665 | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Places a segment of data at the end of the last piece of data stored. | | * Places a segment of data at the end of the last piece of data stored. | |
| * | | * | |
| * @param[in] key key of object whose value we will append data to | | * @param[in] key key of object whose value we will append data to | |
| * @param[in] value data to append to object's value | | * @param[in] value data to append to object's value | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool append(const std::string &key, const std::vector<char> &value) | | bool append(const std::string &key, const std::vector<char> &value) | |
|
| | | throw(Error) | |
| { | | { | |
| if (key.empty() || value.empty()) | | if (key.empty() || value.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the key or value supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_append(&memc, | | memcached_return rc= memcached_append(&memc, | |
| key.c_str(), | | key.c_str(), | |
| key.length(), | | key.length(), | |
| &value[0], | | &value[0], | |
| value.size(), | | value.size(), | |
| 0, 0); | | 0, 0); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 587 | | skipping to change at line 693 | |
| * on is specified by the master_key parameter. | | * on is specified by the master_key parameter. | |
| * | | * | |
| * @param[in] master_key key of server where object is stored | | * @param[in] master_key key of server where object is stored | |
| * @param[in] key key of object whose value we will append data to | | * @param[in] key key of object whose value we will append data to | |
| * @param[in] value data to append to object's value | | * @param[in] value data to append to object's value | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool appendByKey(const std::string &master_key, | | bool appendByKey(const std::string &master_key, | |
| const std::string &key, | | const std::string &key, | |
| const std::vector<char> &value) | | const std::vector<char> &value) | |
|
| | | throw(Error) | |
| { | | { | |
| if (master_key.empty() || | | if (master_key.empty() || | |
| key.empty() || | | key.empty() || | |
| value.empty()) | | value.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the master key or key supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_append_by_key(&memc, | | memcached_return rc= memcached_append_by_key(&memc, | |
| master_key.c_str(), | | master_key.c_str(), | |
| master_key.length(), | | master_key.length(), | |
| key.c_str(), | | key.c_str(), | |
| key.length(), | | key.length(), | |
| &value[0], | | &value[0], | |
| value.size(), | | value.size(), | |
| 0, 0); | | 0, 0); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| | | | |
| skipping to change at line 615 | | skipping to change at line 722 | |
| /** | | /** | |
| * Overwrite data in the server as long as the cas_arg value | | * Overwrite data in the server as long as the cas_arg value | |
| * is still the same in the server. | | * is still the same in the server. | |
| * | | * | |
| * @param[in] key key of object in server | | * @param[in] key key of object in server | |
| * @param[in] value value to store for object in server | | * @param[in] value value to store for object in server | |
| * @param[in] cas_arg "cas" value | | * @param[in] cas_arg "cas" value | |
| */ | | */ | |
| bool cas(const std::string &key, | | bool cas(const std::string &key, | |
| const std::vector<char> &value, | | const std::vector<char> &value, | |
|
| uint64_t cas_arg) | | uint64_t cas_arg) throw(Error) | |
| { | | { | |
| if (key.empty() || value.empty()) | | if (key.empty() || value.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the key or value supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_cas(&memc, key.c_str(), key.length(), | | memcached_return rc= memcached_cas(&memc, key.c_str(), key.length(), | |
| &value[0], value.size(), | | &value[0], value.size(), | |
| 0, 0, cas_arg); | | 0, 0, cas_arg); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Overwrite data in the server as long as the cas_arg value | | * Overwrite data in the server as long as the cas_arg value | |
| * is still the same in the server. The server to use is | | * is still the same in the server. The server to use is | |
| * specified by the master_key parameter. | | * specified by the master_key parameter. | |
| * | | * | |
| * @param[in] master_key specifies server to operate on | | * @param[in] master_key specifies server to operate on | |
| * @param[in] key key of object in server | | * @param[in] key key of object in server | |
| * @param[in] value value to store for object in server | | * @param[in] value value to store for object in server | |
| * @param[in] cas_arg "cas" value | | * @param[in] cas_arg "cas" value | |
| */ | | */ | |
| bool casByKey(const std::string &master_key, | | bool casByKey(const std::string &master_key, | |
| const std::string &key, | | const std::string &key, | |
| const std::vector<char> &value, | | const std::vector<char> &value, | |
|
| uint64_t cas_arg) | | uint64_t cas_arg) throw(Error) | |
| { | | { | |
| if (master_key.empty() || | | if (master_key.empty() || | |
| key.empty() || | | key.empty() || | |
| value.empty()) | | value.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the master key, key or value supplied is empty!", false)
); | |
| } | | } | |
| memcached_return rc= memcached_cas_by_key(&memc, | | memcached_return rc= memcached_cas_by_key(&memc, | |
| master_key.c_str(), | | master_key.c_str(), | |
| master_key.length(), | | master_key.length(), | |
| key.c_str(), | | key.c_str(), | |
| key.length(), | | key.length(), | |
| &value[0], | | &value[0], | |
| value.size(), | | value.size(), | |
| 0, 0, cas_arg); | | 0, 0, cas_arg); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Delete an object from the server specified by the key given. | | * Delete an object from the server specified by the key given. | |
| * | | * | |
| * @param[in] key key of object to delete | | * @param[in] key key of object to delete | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
|
| bool remove(const std::string &key) | | bool remove(const std::string &key) throw(Error) | |
| { | | { | |
| if (key.empty()) | | if (key.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the key supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_delete(&memc, key.c_str(), key.length(),
0); | | memcached_return rc= memcached_delete(&memc, key.c_str(), key.length(),
0); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Delete an object from the server specified by the key given. | | * Delete an object from the server specified by the key given. | |
| * | | * | |
| * @param[in] key key of object to delete | | * @param[in] key key of object to delete | |
| * @param[in] expiration time to delete the object after | | * @param[in] expiration time to delete the object after | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool remove(const std::string &key, | | bool remove(const std::string &key, | |
|
| time_t expiration) | | time_t expiration) throw(Error) | |
| { | | { | |
| if (key.empty()) | | if (key.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the key supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_delete(&memc, | | memcached_return rc= memcached_delete(&memc, | |
| key.c_str(), | | key.c_str(), | |
| key.length(), | | key.length(), | |
| expiration); | | expiration); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Delete an object from the server specified by the key given. | | * Delete an object from the server specified by the key given. | |
| * | | * | |
| * @param[in] master_key specifies server to remove object from | | * @param[in] master_key specifies server to remove object from | |
| * @param[in] key key of object to delete | | * @param[in] key key of object to delete | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool removeByKey(const std::string &master_key, | | bool removeByKey(const std::string &master_key, | |
|
| const std::string &key) | | const std::string &key) throw(Error) | |
| { | | { | |
| if (master_key.empty() || key.empty()) | | if (master_key.empty() || key.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the master key or key supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_delete_by_key(&memc, | | memcached_return rc= memcached_delete_by_key(&memc, | |
| master_key.c_str(), | | master_key.c_str(), | |
| master_key.length(), | | master_key.length(), | |
| key.c_str(), | | key.c_str(), | |
| key.length(), | | key.length(), | |
| 0); | | 0); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| /** | | /** | |
| * Delete an object from the server specified by the key given. | | * Delete an object from the server specified by the key given. | |
| * | | * | |
| * @param[in] master_key specifies server to remove object from | | * @param[in] master_key specifies server to remove object from | |
| * @param[in] key key of object to delete | | * @param[in] key key of object to delete | |
| * @param[in] expiration time to delete the object after | | * @param[in] expiration time to delete the object after | |
| * @return true on success; false otherwise | | * @return true on success; false otherwise | |
| */ | | */ | |
| bool removeByKey(const std::string &master_key, | | bool removeByKey(const std::string &master_key, | |
| const std::string &key, | | const std::string &key, | |
|
| time_t expiration) | | time_t expiration) throw(Error) | |
| { | | { | |
| if (master_key.empty() || key.empty()) | | if (master_key.empty() || key.empty()) | |
| { | | { | |
|
| return false; | | throw(Error("the master key or key supplied is empty!", false)); | |
| } | | } | |
| memcached_return rc= memcached_delete_by_key(&memc, | | memcached_return rc= memcached_delete_by_key(&memc, | |
| master_key.c_str(), | | master_key.c_str(), | |
| master_key.length(), | | master_key.length(), | |
| key.c_str(), | | key.c_str(), | |
| key.length(), | | key.length(), | |
| expiration); | | expiration); | |
| return (rc == MEMCACHED_SUCCESS); | | return (rc == MEMCACHED_SUCCESS); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 791 | | skipping to change at line 898 | |
| */ | | */ | |
| const std::string libVersion() const | | const std::string libVersion() const | |
| { | | { | |
| const char *ver= memcached_lib_version(); | | const char *ver= memcached_lib_version(); | |
| const std::string version(ver); | | const std::string version(ver); | |
| return version; | | return version; | |
| } | | } | |
| | | | |
| private: | | private: | |
| | | | |
|
| | | std::string servers_list; | |
| memcached_st memc; | | memcached_st memc; | |
|
| | | memcached_server_st *servers; | |
| memcached_result_st result; | | memcached_result_st result; | |
| }; | | }; | |
| | | | |
| } | | } | |
| | | | |
| #endif /* LIBMEMCACHEDPP_H */ | | #endif /* LIBMEMCACHEDPP_H */ | |
| | | | |
End of changes. 58 change blocks. |
| 38 lines changed or deleted | | 147 lines changed or added | |
|