| 296 | } |
| 297 | |
| 298 | static void hspool_find(const char* addr, int num, bool enable_cache) |
| 299 | { |
| 300 | const char* dbn = "test", *tbl = "user", *idx; |
| 301 | const char* flds = "user_id,user_name,user_email"; |
| 302 | char buf[256]; |
| 303 | const char* addr_rd = "192.168.1.232:9998"; |
| 304 | acl::hspool pool(addr, addr_rd, enable_cache); |
| 305 | acl::hsclient* client; |
| 306 | |
| 307 | idx = "PRIMARY"; |
| 308 | for (int i = 0; i < 10; i++) |
| 309 | { |
| 310 | client = pool.peek(dbn, tbl, idx, flds); |
| 311 | if (client == NULL) |
| 312 | { |
| 313 | printf("peek error\n"); |
| 314 | break; |
| 315 | } |
| 316 | printf(">>read addr: %s\n", client->get_addr()); |
| 317 | pool.put(client); |
| 318 | } |
| 319 | |
| 320 | printf("========================================================\n"); |
| 321 | |
| 322 | for (int i = 0; i < 10; i++) |
| 323 | { |
| 324 | client = pool.peek(dbn, tbl, idx, flds); |
| 325 | if (client == NULL) |
| 326 | { |
| 327 | printf("peek error\n"); |
| 328 | break; |
| 329 | } |
| 330 | printf(">>read/write addr: %s\n", client->get_addr()); |
| 331 | pool.put(client); |
| 332 | } |
| 333 | |
| 334 | ////////////////////////////////////////////////////////////////////// |
| 335 | |
| 336 | printf("========================================================\n"); |
| 337 | idx = "PRIMARY"; |
| 338 | for (int i = 0; i < num; i++) |
| 339 | { |
| 340 | snprintf(buf, sizeof(buf), "%d", i); |
| 341 | |
| 342 | client = pool.peek(dbn, tbl, idx, flds); |
| 343 | if (client == NULL) |
| 344 | { |
| 345 | printf("peek error\n"); |
| 346 | break; |
| 347 | } |
| 348 | |
| 349 | const std::vector<acl::hsrow*>& rows = |
| 350 | client->get(buf, NULL); |
| 351 | if (rows.empty()) |
| 352 | { |
| 353 | printf("find(%s) error\n", buf); |
| 354 | pool.put(client); |
| 355 | break; |