120int main(
int argc,
char** argv) {
123 int option_index = 0;
124 int min_version = -1, max_version = -1;
125 std::string min_key, max_key;
127 std::string client_config_file;
134 if (cmd ==
"get" || cmd ==
"set" || cmd ==
"getvalues" ||
141 while ((c = getopt_long(argc, argv,
"h", long_options, &option_index)) !=
145 client_config_file = optarg;
157 version = strtoull(optarg, NULL, 10);
160 min_version = strtoull(optarg, NULL, 10);
163 max_version = strtoull(optarg, NULL, 10);
172 top = strtoull(optarg, NULL, 10);
180 ResDBConfig config = GenerateResDBConfig(client_config_file);
184 if (cmd ==
"set_with_version") {
185 if (key.empty() || value.empty() || version < 0) {
189 int ret = client.
Set(key, value, version);
190 printf(
"set key = %s, value = %s, version = %d done, ret = %d\n",
191 key.c_str(), value.c_str(), version, ret);
194 auto res = client.
Get(key, 0);
195 if (res !=
nullptr) {
196 printf(
"current value = %s\n", res->DebugString().c_str());
198 printf(
"get value fail\n");
201 }
else if (cmd ==
"set") {
202 if (key.empty() || value.empty()) {
206 int ret = client.
Set(key, value);
207 printf(
"set key = %s, value = %s done, ret = %d\n", key.c_str(),
209 }
else if (cmd ==
"get_with_version") {
210 auto res = client.
Get(key, version);
211 if (res !=
nullptr) {
212 printf(
"get key = %s, value = %s\n", key.c_str(),
213 res->DebugString().c_str());
215 printf(
"get value fail\n");
217 }
else if (cmd ==
"get") {
218 auto res = client.
Get(key);
219 if (res !=
nullptr) {
220 printf(
"get key = %s value = %s\n", key.c_str(), res->c_str());
222 printf(
"get value fail\n");
224 }
else if (cmd ==
"get_top") {
226 if (res !=
nullptr) {
227 printf(
"key = %s, top %d\n value = %s\n", key.c_str(), top,
228 res->DebugString().c_str());
230 printf(
"get key = %s top %d value fail\n", key.c_str(), top);
232 }
else if (cmd ==
"get_history") {
233 if (key.empty() || min_version < 0 || max_version < 0 ||
234 max_version < min_version) {
238 auto res = client.
GetKeyHistory(key, min_version, max_version);
239 if (res !=
nullptr) {
241 "get history key = %s, min version = %d, max version = %d\n value = "
243 key.c_str(), min_version, max_version, res->DebugString().c_str());
246 "get history key = %s, min version = %d, max version = %d value "
248 key.c_str(), min_version, max_version);
250 }
else if (cmd ==
"get_key_range") {
251 if (min_key.empty() || max_key.empty() || min_key > max_key) {
255 auto res = client.
GetRange(min_key, max_key);
256 if (res !=
nullptr) {
257 printf(
"getrange min key = %s, max key = %s\n value = %s\n",
258 min_key.c_str(), max_key.c_str(), (*res).c_str());
260 printf(
"getrange value fail, min key = %s, max key = %s\n",
261 min_key.c_str(), max_key.c_str());
263 }
else if (cmd ==
"get_key_range_with_version") {
264 if (min_key.empty() || max_key.empty() || min_key > max_key) {
268 printf(
"min key = %s max key = %s\n", min_key.c_str(), max_key.c_str());
270 if (res !=
nullptr) {
271 printf(
"getrange min key = %s, max key = %s\n value = %s\n",
272 min_key.c_str(), max_key.c_str(), res->DebugString().c_str());
274 printf(
"getrange value fail, min key = %s, max key = %s\n",
275 min_key.c_str(), max_key.c_str());