MCPcopy Create free account
hub / github.com/acl-dev/acl / ask

Method ask

lib_acl_cpp/src/redis/redis_client_cluster.cpp:394–447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

392}
393
394redis_client* redis_client_cluster::ask(redis_command& cmd,
395 redis_client* conn, const char* ptr, int ntried)
396{
397 // �������Ӷ���黹�����ӳض���
398 conn->get_pool()->put(conn, true);
399
400 const char* addr = cmd.get_addr(ptr);
401 if (addr == NULL) {
402 logger_warn("ASK invalid, ptr: %s", ptr);
403 return NULL;
404 }
405
406 // �����ӳؼ�������ȡĿ��redis�ڵ���������������ڣ���Ĭ��ʹ��
407 // �����õĵ�һ��redis�ڵ��������
408 const conn_config* conf = this->get_config(addr, true);
409 if (conf == NULL) {
410 logger_error("no conn_config for addr=%s", addr);
411 return NULL;
412 }
413
414 conn = redirect(addr, conf->max);
415 if (conn == NULL) {
416 logger_error("redirect NULL, addr: %s", addr);
417 return NULL;
418 }
419
420 ptr = conn->get_pool()->get_addr();
421 cmd.set_client_addr(ptr);
422
423 if (ntried >= 2 && redirect_sleep_ > 0 && strcmp(ptr, addr) != 0) {
424 logger("redirect %d, curr %s, waiting %s ...",
425 ntried, ptr, addr);
426 acl_doze(redirect_sleep_);
427 }
428
429 dbuf_pool* dbuf = cmd.get_dbuf();
430 const redis_result* result = conn->run(dbuf, "ASKING\r\n", 0);
431 if (result == NULL) {
432 logger_error("ASKING's reply null");
433 conn->get_pool()->put(conn, !conn->eof());
434 return NULL;
435 }
436
437 const char* status = result->get_status();
438 if (status == NULL || strcasecmp(status, "OK") != 0) {
439 logger_error("ASKING's reply error: %s",
440 status ? status : "null");
441 conn->get_pool()->put(conn, !conn->eof());
442 return NULL;
443 }
444
445 cmd.clear(true);
446 return conn;
447}
448
449redis_client* redis_client_cluster::cluster_down(redis_command& cmd,
450 redis_client* conn, const char* ptr, int ntried)

Callers

nothing calls this directly

Calls 10

acl_dozeFunction · 0.85
get_configMethod · 0.80
set_client_addrMethod · 0.80
get_dbufMethod · 0.80
putMethod · 0.45
get_addrMethod · 0.45
runMethod · 0.45
eofMethod · 0.45
get_statusMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected