-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
43 lines (37 loc) · 1.21 KB
/
example.cpp
File metadata and controls
43 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Example usage of MemcachedClient class.
* Author: Irfan Hamid
*/
#include "src/MemcachedClient.h"
#include <iostream>
#include <stdexcept>
int main() {
try {
MemcachedClient memcached;
// Attempt to store a value
const std::string key = "my_key";
const std::string value = "my_value";
if (memcached.set(key, value)) {
std::cout << "Value stored successfully for key: " << key << std::endl;
} else {
std::cerr << "Failed to store value for key: " << key << std::endl;
return 1; // Exit with error code
}
// Attempt to retrieve the stored value
std::string retrievedValue = memcached.get(key);
if (!retrievedValue.empty()) {
std::cout << "Retrieved value for key '" << key << "': " << retrievedValue
<< std::endl;
} else {
std::cerr << "Failed to retrieve value for key: " << key << std::endl;
return 1; // Exit with error code
}
} catch (const std::exception &ex) {
std::cerr << "An error occurred: " << ex.what() << std::endl;
return 1; // Exit with error code
} catch (...) {
std::cerr << "An unknown error occurred." << std::endl;
return 1; // Exit with error code
}
return 0; // Exit successfully
}