// File: 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
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1d8(%rbp)
cmpq $0x0, 0x8(%rax)
jne 0x6929
movb $0x0, -0x1(%rbp)
jmp 0x704f
movl $0x0, -0x34(%rbp)
movl $0x64, -0x38(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x6944
movl $0x7fffffff, -0x24(%rbp) # imm = 0x7FFFFFFF
movq -0x30(%rbp), %rdi
callq 0xb890
movq -0x30(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0xb8b0
movq -0x1d8(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
leaq -0x34(%rbp), %rdx
callq 0x4560
movq -0x1e0(%rbp), %rdx
leaq 0x11847(%rip), %rsi     # 0x181cd
leaq -0x98(%rbp), %rdi
callq 0xb840
jmp 0x6994
movq -0x20(%rbp), %rdi
callq 0x3610
movb $0x0, -0xea(%rbp)
testb $0x1, %al
jne 0x69aa
jmp 0x69e2
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x3670
movq -0x1e8(%rbp), %rdx
movb $0x1, -0xea(%rbp)
leaq 0x118a8(%rip), %rsi     # 0x1827a
leaq -0xe8(%rbp), %rdi
callq 0x3510
jmp 0x69e0
jmp 0x69fd
movq -0x20(%rbp), %rdx
leaq 0x11700(%rip), %rsi     # 0x180ed
leaq -0xe8(%rbp), %rdi
callq 0xb510
jmp 0x69fb
jmp 0x69fd
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0xb620
jmp 0x6a16
movl -0x38(%rbp), %eax
movb $0x0, -0x112(%rbp)
movb $0x0, -0x139(%rbp)
cmpl $0x0, %eax
jge 0x6a64
leaq -0x111(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x3670
movq -0x1f0(%rbp), %rdx
movb $0x1, -0x112(%rbp)
leaq 0x11826(%rip), %rsi     # 0x1827a
leaq -0x110(%rbp), %rdi
callq 0x3510
jmp 0x6a62
jmp 0x6aa2
movq -0x1d8(%rbp), %rsi
leaq -0x138(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0x4560
jmp 0x6a7d
movb $0x1, -0x139(%rbp)
leaq 0x1166a(%rip), %rsi     # 0x180f5
leaq -0x110(%rbp), %rdi
leaq -0x138(%rbp), %rdx
callq 0xb840
jmp 0x6aa0
jmp 0x6aa2
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0xb620
jmp 0x6ab8
leaq -0x110(%rbp), %rdi
callq 0x3290
testb $0x1, -0x139(%rbp)
jne 0x6acf
jmp 0x6adb
leaq -0x138(%rbp), %rdi
callq 0x3290
testb $0x1, -0x112(%rbp)
jne 0x6ae6
jmp 0x6af2
leaq -0x111(%rbp), %rdi
callq 0x3410
leaq -0x78(%rbp), %rdi
callq 0x3290
leaq -0xe8(%rbp), %rdi
callq 0x3290
testb $0x1, -0xea(%rbp)
jne 0x6b12
jmp 0x6b1e
leaq -0xe9(%rbp), %rdi
callq 0x3410
leaq -0x98(%rbp), %rdi
callq 0x3290
leaq -0xb8(%rbp), %rdi
callq 0x3290
movq -0x1d8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x200(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3190
movq -0x200(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x11a60
movq %rax, -0x1f8(%rbp)
jmp 0x6b6b
movq -0x1d8(%rbp), %rdi
movq -0x1f8(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rsi
callq 0x59f0
testb $0x1, %al
jne 0x6b95
jmp 0x6cd5
movq -0x1d8(%rbp), %rdi
movq -0x148(%rbp), %rsi
callq 0x59c0
jmp 0x6baa
movb $0x0, -0x1(%rbp)
movl $0x1, -0x14c(%rbp)
jmp 0x6fac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x6cad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x6c8a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x6c7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x6c5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x6c45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x3290
testb $0x1, -0x139(%rbp)
jne 0x6c50
jmp 0x6c5c
leaq -0x138(%rbp), %rdi
callq 0x3290
jmp 0x6c5e
testb $0x1, -0x112(%rbp)
jne 0x6c69
jmp 0x6c75
leaq -0x111(%rbp), %rdi
callq 0x3410
leaq -0x78(%rbp), %rdi
callq 0x3290
leaq -0xe8(%rbp), %rdi
callq 0x3290
testb $0x1, -0xea(%rbp)
jne 0x6c95
jmp 0x6ca1
leaq -0xe9(%rbp), %rdi
callq 0x3410
leaq -0x98(%rbp), %rdi
callq 0x3290
leaq -0xb8(%rbp), %rdi
callq 0x3290
jmp 0x705d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x7044
movq -0x148(%rbp), %rax
cmpl $0x2, (%rax)
je 0x6d09
movq -0x1d8(%rbp), %rdi
movq -0x148(%rbp), %rsi
callq 0x59c0
jmp 0x6cf6
movb $0x0, -0x1(%rbp)
movl $0x1, -0x14c(%rbp)
jmp 0x6fac
movq -0x148(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rax
movq 0x20(%rax), %rax
movl %eax, -0x15c(%rbp)
movl $0x0, -0x160(%rbp)
movl -0x160(%rbp), %eax
cmpl -0x15c(%rbp), %eax
jae 0x6ef7
movq -0x158(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x160(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x210(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x218(%rbp)
leaq -0x181(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x3670
movq -0x218(%rbp), %rsi
movq -0x210(%rbp), %rdx
movq -0x208(%rbp), %rcx
leaq -0x180(%rbp), %rdi
callq 0x3450
jmp 0x6dad
leaq -0x181(%rbp), %rdi
callq 0x3410
movq -0x18(%rbp), %rdi
callq 0x3610
testb $0x1, %al
jne 0x6dc8
jmp 0x6e25
movq -0x30(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0xb9b0
jmp 0x6dda
jmp 0x6e9f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x181(%rbp), %rdi
callq 0x3410
jmp 0x7044
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x3290
jmp 0x7044
movq -0x1d8(%rbp), %rsi
leaq -0x1a8(%rbp), %rdi
leaq -0x180(%rbp), %rdx
callq 0x7070
jmp 0x6e41
leaq -0x1a8(%rbp), %rdi
callq 0x3190
movq %rax, -0x228(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3190
movq -0x228(%rbp), %rdi
movq %rax, %rsi
callq 0x3430
movl %eax, -0x21c(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x3290
movl -0x21c(%rbp), %eax
cmpl $0x0, %eax
jne 0x6e9d
movq -0x30(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0xb9b0
jmp 0x6e9b
jmp 0x6e9d
jmp 0x6e9f
movq -0x30(%rbp), %rdi
callq 0x4540
movslq -0x24(%rbp), %rcx
cmpq %rcx, %rax
jb 0x6ebd
movl $0x4, -0x14c(%rbp)
jmp 0x6ec7
movl $0x0, -0x14c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x3290
movl -0x14c(%rbp), %eax
testl %eax, %eax
je 0x6ee1
jmp 0x6edf
jmp 0x6ef7
jmp 0x6ee3
movl -0x160(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x160(%rbp)
jmp 0x6d3a
movq -0x148(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x238(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x240(%rbp)
leaq -0x1c9(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x3670
movq -0x240(%rbp), %rsi
movq -0x238(%rbp), %rdx
movq -0x230(%rbp), %rcx
leaq -0x1c8(%rbp), %rdi
callq 0x3450
jmp 0x6f51
leaq -0x1c9(%rbp), %rdi
callq 0x3410
movq -0x1d8(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0xba20
movl %eax, -0x244(%rbp)
jmp 0x6f78
movq -0x1d8(%rbp), %rdi
movl -0x244(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x148(%rbp), %rsi
callq 0x59c0
jmp 0x6f96
leaq -0x1c8(%rbp), %rdi
callq 0x3290
movl $0x0, -0x14c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3290
movl -0x14c(%rbp), %eax
testl %eax, %eax
je 0x6fc6
jmp 0x6fc1
jmp 0x704f
jmp 0x6fc8
movq -0x30(%rbp), %rdi
callq 0x4540
movq %rax, %rcx
movslq -0x24(%rbp), %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x245(%rbp)
jae 0x6ff2
cmpl $0x0, -0x34(%rbp)
setne %al
movb %al, -0x245(%rbp)
movb -0x245(%rbp), %al
testb $0x1, %al
jne 0x695a
movb $0x1, -0x1(%rbp)
jmp 0x704f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x1c9(%rbp), %rdi
callq 0x3410
jmp 0x7044
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x3290
leaq -0x58(%rbp), %rdi
callq 0x3290
jmp 0x705d
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
movq -0xc0(%rbp), %rdi
callq 0x3660
nopl (%rax)