| 495 | } |
| 496 | |
| 497 | disque_node* disque::create_node(const redis_result* rr) |
| 498 | { |
| 499 | if (rr->get_type() != REDIS_RESULT_ARRAY) { |
| 500 | return NULL; |
| 501 | } |
| 502 | |
| 503 | size_t n; |
| 504 | const redis_result** children = rr->get_children(&n); |
| 505 | if (n < 4) { |
| 506 | return NULL; |
| 507 | } |
| 508 | |
| 509 | if (children[0]->get_type() != REDIS_RESULT_STRING) { |
| 510 | return NULL; |
| 511 | } |
| 512 | string id; |
| 513 | children[0]->argv_to_string(id); |
| 514 | |
| 515 | if (children[1]->get_type() != REDIS_RESULT_STRING) { |
| 516 | return NULL; |
| 517 | } |
| 518 | string ip; |
| 519 | children[1]->argv_to_string(ip); |
| 520 | |
| 521 | if (children[2]->get_type() != REDIS_RESULT_STRING) { |
| 522 | return NULL; |
| 523 | } |
| 524 | string tmp; |
| 525 | children[2]->argv_to_string(tmp); |
| 526 | int port = ::atoi(tmp.c_str()); |
| 527 | |
| 528 | if (children[3]->get_type() != REDIS_RESULT_STRING) { |
| 529 | return NULL; |
| 530 | } |
| 531 | children[3]->argv_to_string(tmp); |
| 532 | int priority = ::atoi(tmp.c_str()); |
| 533 | |
| 534 | disque_node* node = NEW disque_node; |
| 535 | node->set_id(id.c_str()); |
| 536 | node->set_ip(ip.c_str()); |
| 537 | node->set_port(port); |
| 538 | node->set_priority(priority); |
| 539 | |
| 540 | return node; |
| 541 | } |
| 542 | |
| 543 | void disque::free_nodes(void) |
| 544 | { |