// File: /workspace/github_cpp_makefile_star2_O2/Sherhang[P]redis-for-cpp/credis.cpp
// Function: Redis::getKeys(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
bool Redis::getKeys(const std::string& yourType, const std::string& pattern, int32_t maxNum, std::vector<std::string>& keys)
{
    if(_context==NULL)
    {
        //DEBUG<<"NULL"<<std::endl;
        return false;
    }
    int32_t cursor = 0;
    int32_t count = 100;
    if(maxNum<0)
    {
        maxNum = 0x7fffffff;
    }
    //DEBUG<<"maxNum "<<maxNum<<std::endl;
    
    keys.clear();
    keys.reserve(maxNum);
    do
    {
        std::string cmd = "SCAN "  + num2str<int32_t>(cursor)
                    + (pattern.empty() ? "" : (" MATCH " + pattern))
                    + (count < 0 ? "" : " COUNT " + num2str<int32_t>(count));
        redisReply* _reply = (redisReply*)::redisCommand(_context, cmd.c_str());
        if(isError(_reply))
        {
            //DEBUG<<"isError"<<std::endl;
            freeReply(_reply);
            return false;
        }
        //DEBUG<<"_reply->type "<<_reply->type<<std::endl;
        if(_reply->type != REDIS_REPLY_ARRAY)
        {
            //DEBUG<<"not array"<<std::endl;
            freeReply(_reply);
            return false;
        }
        redisReply* sub_reply = (_reply->element[1]);
        uint32_t len = sub_reply->elements;
        for(uint32_t i=0;i<len;++i)
        {
            std::string strTemp(sub_reply->element[i]->str, sub_reply->element[i]->len);
            if(yourType.empty())
            {
                keys.push_back(strTemp);
            }
            else if(strcasecmp((type(strTemp)).c_str(), yourType.c_str() ) == 0)
                 {
                    keys.push_back(strTemp);
                 }
            if(keys.size() >= maxNum)
            {
                //DEBUG
                break;
            }
        }
        
        std::string strTemp(_reply->element[0]->str, _reply->element[0]->len);
        cursor = str2num<int32_t>(strTemp);//update cursor
        freeReply(_reply);
        //DEBUG<<keys.size()<<" "<<cursor<<std::endl;

    } while(keys.size() < maxNum && cursor!=0);
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, 0x28(%rsp)
movq %rdi, 0x8(%rsp)
cmpq $0x0, 0x8(%rdi)
je 0x4f9b
movq %r8, %rbx
movq %rdx, %r14
movq %rsp, %rax
andl $0x0, (%rax)
leaq 0x14(%rsp), %rax
movl $0x64, (%rax)
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
cmpl %r12d, %ecx
cmovbl %ecx, %r12d
movq %r8, %rdi
callq 0x79b8
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
movq %r12, 0x20(%rsp)
movq %r12, %rsi
callq 0x79c0
leaq 0x58(%rsp), %rbp
movq %r14, 0x50(%rsp)
leaq 0xf8(%rsp), %r12
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq %rsp, %rdx
callq 0x3de4
leaq 0x78(%rsp), %r13
movq %r13, %rdi
leaq 0xc4bb(%rip), %rsi      # 0x111cd
movq %r12, %rdx
callq 0x7994
movq 0x8(%r14), %r12
testq %r12, %r12
je 0x4d37
movq %rbp, %rdi
leaq 0xc3c0(%rip), %rsi      # 0x110ed
movq %r14, %rdx
callq 0x7822
jmp 0x4d4b
movq %rbp, %rdi
leaq 0xc563(%rip), %rsi      # 0x112a4
leaq 0x7(%rsp), %rdx
callq 0x3140
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x7898
movl 0x14(%rsp), %ebp
testl %ebp, %ebp
js 0x4d99
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
leaq 0x14(%rsp), %rdx
callq 0x3de4
leaq 0xd8(%rsp), %r15
movq %r15, %rdi
leaq 0xc366(%rip), %rsi      # 0x110f5
movq %rbx, %rdx
callq 0x7994
jmp 0x4db5
leaq 0xd8(%rsp), %r15
movq %r15, %rdi
leaq 0xc4f9(%rip), %rsi      # 0x112a4
leaq 0x6(%rsp), %rdx
callq 0x3140
leaq 0x98(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq %r15, %rdx
callq 0x7898
movq %r15, %rdi
callq 0x3180
testl %ebp, %ebp
js 0x4de3
leaq 0xb8(%rsp), %rdi
callq 0x3180
leaq 0x58(%rsp), %rbp
leaq 0x30(%rsp), %rdi
callq 0x3180
movq %rbp, %rdi
callq 0x3180
testq %r12, %r12
movq %r13, %rdi
callq 0x3180
leaq 0xf8(%rsp), %rdi
callq 0x3180
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x98(%rsp), %rsi
xorl %eax, %eax
callq 0xb190
movq %rax, %rbx
testq %rax, %rax
je 0x4f4f
cmpl $0x2, (%rbx)
jne 0x4f5b
movq 0x28(%rbx), %rax
movq 0x8(%rax), %rbp
movl 0x20(%rbp), %r15d
xorl %r14d, %r14d
leaq 0x30(%rsp), %r13
cmpq %r14, %r15
je 0x4efc
movq 0x28(%rbp), %rax
movq (%rax,%r14,8), %rax
movq 0x18(%rax), %rsi
movq 0x10(%rax), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %r13, %rdi
callq 0x7cd0
movq 0x28(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x4ec9
movq %r13, %rdx
leaq 0x78(%rsp), %r13
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0x504a
movq 0x78(%rsp), %rdi
movq 0x28(%rsp), %rax
movq (%rax), %rsi
callq 0x33b0
movl %eax, %r12d
movq %r13, %rdi
callq 0x3180
testl %r12d, %r12d
leaq 0x30(%rsp), %r13
jne 0x4ed6
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x7a4c
movq 0x18(%rsp), %rax
movq 0x8(%rax), %r12
subq (%rax), %r12
sarq $0x5, %r12
movq %r13, %rdi
callq 0x3180
incq %r14
cmpq 0x20(%rsp), %r12
jb 0x4e53
movq 0x28(%rbx), %rax
movq (%rax), %rax
movq 0x18(%rax), %rsi
movq 0x10(%rax), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %r13, %rdi
callq 0x7cd0
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x7a78
movq 0x50(%rsp), %r14
leaq 0x58(%rsp), %rbp
movl %eax, (%rsp)
movq %rbx, %rdi
callq 0x8ae0
movq %r13, %rdi
callq 0x3180
movb $0x1, %r13b
jmp 0x4f66
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x43f8
jmp 0x4f66
movq %rbx, %rdi
callq 0x8ae0
xorl %r13d, %r13d
leaq 0x98(%rsp), %rdi
callq 0x3180
testb %r13b, %r13b
je 0x4f9e
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
sarq $0x5, %rax
cmpq 0x20(%rsp), %rax
jae 0x4f9e
cmpl $0x0, (%rsp)
jne 0x4ceb
jmp 0x4f9e
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5031
jmp 0x4fb9
jmp 0x5022
movq %rax, %rbx
jmp 0x4fe9
movq %rax, %rbx
jmp 0x4fdc
movq %rax, %rbx
jmp 0x5002
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x3180
testl %ebp, %ebp
js 0x4fe9
leaq 0xb8(%rsp), %rdi
callq 0x3180
leaq 0x30(%rsp), %rdi
callq 0x3180
jmp 0x4ff8
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x3180
testq %r12, %r12
leaq 0x78(%rsp), %rdi
callq 0x3180
leaq 0xf8(%rsp), %rdi
jmp 0x503c
movq %rax, %rbx
jmp 0x500f
jmp 0x5031
jmp 0x5022
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3180
jmp 0x5034
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x3180
movq %rbx, %rdi
callq 0x35a0
nop