// File: Sherhang[P]redis-for-cpp/redis_connect_pool.cpp
// Function: RedisConnectPool::connect()
redisContext * RedisConnectPool::connect()
{
    redisContext *redisConn = NULL;
    redisConn = redisConnect(_redisIP.c_str(), _redisProt);
    if(redisConn != NULL && redisConn->err)
    {
        if (redisConn->errstr != NULL)
        {
        }
        
        if (NULL != redisConn)
        {
            redisFree(redisConn);
        }
        redisConn = NULL;
        return NULL;
    }
    if (!_needPasswd ) 
    {
        //debug 
        return redisConn;
    }
    std::string cmd = "AUTH " + (_passwd.empty()? "1245678" : _passwd);
    redisReply *reply = (redisReply*)::redisCommand(redisConn, cmd.c_str());
    if (reply == NULL && redisConn->err != 0)
    {
        return NULL;
    }

    if (reply->type == REDIS_REPLY_STATUS && strcasecmp(reply->str, "OK") != 0)
    {
        return NULL;
    }
    if (reply->type == REDIS_REPLY_ERROR) 
    {
        if (strcasecmp(reply->str, "ERR Client sent AUTH, but no password is set") == 0) 
        {
            _needPasswd = false;
            reConnect(redisConn);
        } 
        else 
        {
            return NULL;
        }
    }
    if(reply)
    {
        freeReplyObject(reply);
        reply = NULL;
    }
    
    return redisConn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x88(%rbp)
movq $0x0, -0x18(%rbp)
addq $0x8, %rdi
callq 0x3190
movq %rax, %rdi
movq -0x88(%rbp), %rax
movl 0x48(%rax), %esi
callq 0x10f60
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xe1a7
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xe1a7
movq -0x18(%rbp), %rax
addq $0x4, %rax
cmpq $0x0, %rax
je 0xe181
jmp 0xe181
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
je 0xe192
movq -0x18(%rbp), %rdi
callq 0x10ca0
movq $0x0, -0x18(%rbp)
movq $0x0, -0x8(%rbp)
jmp 0xe3ba
movq -0x88(%rbp), %rax
testb $0x1, 0x90(%rax)
jne 0xe1c4
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xe3ba
movq -0x88(%rbp), %rdi
addq $0x28, %rdi
callq 0x3610
movb $0x0, -0x5a(%rbp)
testb $0x1, %al
jne 0xe1de
jmp 0xe20d
leaq -0x59(%rbp), %rdi
movq %rdi, -0x90(%rbp)
callq 0x3670
movq -0x90(%rbp), %rdx
movb $0x1, -0x5a(%rbp)
leaq 0xa02b(%rip), %rsi      # 0x1822b
leaq -0x58(%rbp), %rdi
callq 0x3510
jmp 0xe20b
jmp 0xe225
movq -0x88(%rbp), %rsi
addq $0x28, %rsi
leaq -0x58(%rbp), %rdi
callq 0x31a0
jmp 0xe223
jmp 0xe225
leaq 0x9fcf(%rip), %rsi      # 0x181fb
leaq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0xb840
jmp 0xe23b
leaq -0x58(%rbp), %rdi
callq 0x3290
testb $0x1, -0x5a(%rbp)
jne 0xe24c
jmp 0xe255
leaq -0x59(%rbp), %rdi
callq 0x3410
movq -0x18(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3190
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x11a60
movq %rax, -0x98(%rbp)
jmp 0xe283
movq -0x98(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0xe305
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xe305
movq $0x0, -0x8(%rbp)
movl $0x1, -0x7c(%rbp)
jmp 0xe3b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xe2d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3290
testb $0x1, -0x5a(%rbp)
jne 0xe2dd
jmp 0xe2e6
leaq -0x59(%rbp), %rdi
callq 0x3410
jmp 0xe3c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3290
jmp 0xe3c7
movq -0x78(%rbp), %rax
cmpl $0x5, (%rax)
jne 0xe338
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0x9df7(%rip), %rsi      # 0x18114
callq 0x3430
cmpl $0x0, %eax
je 0xe338
movq $0x0, -0x8(%rbp)
movl $0x1, -0x7c(%rbp)
jmp 0xe3b1
movq -0x78(%rbp), %rax
cmpl $0x6, (%rax)
jne 0xe388
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0x9ee3(%rip), %rsi      # 0x18233
callq 0x3430
cmpl $0x0, %eax
jne 0xe375
movq -0x88(%rbp), %rdi
movb $0x0, 0x90(%rdi)
leaq -0x18(%rbp), %rsi
callq 0xe3d0
jmp 0xe373
jmp 0xe386
movq $0x0, -0x8(%rbp)
movl $0x1, -0x7c(%rbp)
jmp 0xe3b1
jmp 0xe388
cmpq $0x0, -0x78(%rbp)
je 0xe3a2
movq -0x78(%rbp), %rdi
callq 0xf3b0
jmp 0xe39a
movq $0x0, -0x78(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x7c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3290
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x3660