Work inspired by matt knox
[m6w6/libmemcached] / libmemcached / memcached.hh
1 #include "libmemcached/memcached.h"
2 #include <string.h>
3 #include <stdio.h>
4
5 class Memcached
6 {
7 memcached_st memc;
8 memcached_result_st result;
9
10 public:
11
12 Memcached() : memc(), result()
13 {
14 memcached_create(&memc);
15 }
16
17 Memcached(memcached_st *clone) : memc(), result()
18 {
19 memcached_clone(&memc, clone);
20 }
21 char *fetch (char *key, size_t *key_length, size_t *value_length)
22 {
23 uint32_t flags;
24 memcached_return rc;
25
26 return memcached_fetch(&memc, key, key_length,
27 value_length, &flags, &rc);
28 }
29 char *get(const char *key, size_t *value_length)
30 {
31 uint32_t flags;
32 memcached_return rc;
33
34 return memcached_get(&memc, key, strlen(key),
35 value_length, &flags, &rc);
36 }
37
38 char *get_by_key(const char *master_key, const char *key,
39 size_t *value_length)
40 {
41 uint32_t flags;
42 memcached_return rc;
43
44 return memcached_get_by_key(&memc, master_key, strlen(master_key),
45 key, strlen(key),
46 value_length, &flags, &rc);
47 }
48
49 memcached_return mget(char **keys, size_t *key_length,
50 unsigned int number_of_keys)
51 {
52
53 return memcached_mget(&memc, keys, key_length, number_of_keys);
54 }
55
56 memcached_return set(const char *key, const char *value, size_t value_length)
57 {
58 return memcached_set(&memc, key, strlen(key),
59 value, value_length,
60 time_t(0), uint32_t(0));
61 }
62
63 memcached_return set_by_key(const char *master_key, const char *key,
64 const char *value, size_t value_length)
65 {
66 return memcached_set_by_key(&memc, master_key, strlen(master_key),
67 key, strlen(key),
68 value, value_length,
69 time_t(0),
70 uint32_t(0) );
71 }
72 memcached_return
73 increment(const char *key, unsigned int offset, uint64_t *value)
74 {
75 return memcached_increment(&memc, key, strlen(key),
76 offset, value);
77 }
78 memcached_return
79 decrement(const char *key, unsigned int offset, uint64_t *value)
80 {
81 return memcached_decrement(&memc, key, strlen(key),
82 offset, value);
83 }
84
85
86 memcached_return add(const char *key, const char *value, size_t value_length)
87 {
88 return memcached_add(&memc, key, strlen(key), value, value_length, 0, 0);
89 }
90 memcached_return add_by_key(const char *master_key, const char *key,
91 const char *value, size_t value_length)
92 {
93 return memcached_add_by_key(&memc, master_key, strlen(master_key),
94 key, strlen(key),
95 value, value_length,
96 0, 0);
97 }
98
99 memcached_return replace(const char *key, const char *value,
100 size_t value_length)
101 {
102 return memcached_replace(&memc, key, strlen(key),
103 value, value_length,
104 0, 0);
105 }
106 memcached_return replace_by_key(const char *master_key, const char *key,
107 const char *value, size_t value_length)
108 {
109 return memcached_replace_by_key(&memc, master_key, strlen(master_key),
110 key, strlen(key),
111 value, value_length, 0, 0);
112 }
113
114 memcached_return prepend(const char *key, const char *value,
115 size_t value_length)
116 {
117 return memcached_prepend(&memc, key, strlen(key),
118 value, value_length, 0, 0);
119 }
120 memcached_return prepend_by_key(const char *master_key, const char *key,
121 const char *value, size_t value_length)
122 {
123 return memcached_prepend_by_key(&memc, master_key, strlen(master_key),
124 key, strlen(key),
125 value, value_length,
126 0,
127 0);
128 }
129
130 memcached_return append(const char *key, const char *value,
131 size_t value_length)
132 {
133 return memcached_append(&memc, key, strlen(key),
134 value, value_length, 0, 0);
135 }
136 memcached_return append_by_key(const char *master_key, const char *key,
137 const char *value, size_t value_length)
138 {
139 return memcached_append_by_key(&memc,
140 master_key, strlen(master_key),
141 key, strlen(key),
142 value, value_length, 0, 0);
143 }
144 memcached_return cas(const char *key, const char *value,
145 size_t value_length, uint64_t cas)
146 {
147 return memcached_cas(&memc, key, strlen(key),
148 value, value_length, 0, 0, cas);
149 }
150 memcached_return cas_by_key(const char *master_key, const char *key,
151 const char *value, size_t value_length,
152 uint64_t cas)
153 {
154 return memcached_cas_by_key(&memc,
155 master_key, strlen(master_key),
156 key, strlen(key),
157 value, value_length,
158 0, 0, cas);
159 }
160 // using 'remove' vs. 'delete' since 'delete' is a keyword
161 memcached_return remove(const char *key)
162 {
163 return memcached_delete (&memc, key, strlen(key), 0);
164
165 }
166 memcached_return delete_by_key(const char *master_key, const char *key)
167 {
168 return memcached_delete_by_key(&memc, master_key, strlen(master_key),
169 key, strlen(key), 0);
170 }
171 ~Memcached()
172 {
173 memcached_free(&memc);
174 }
175 };