// File: /workspace/github_cpp_makefile_star2_O2/Sherhang[P]redis-for-cpp/demo4.cpp
// Function: main
int main()
{   int pool_size = 100;
    string ip = "127.0.0.1";
    int port = 6379;
    string passwd ="yehang";
    RedisConnectPool rc_pool;
    if(!rc_pool.init(pool_size, ip, port, passwd))
    {
        cout<<"rc_pool init failure!"<<endl;
        exit(0);
    }
    
    //1
    cout<<"used num : "<<rc_pool.getUsedCount()<<endl;
    cout<<"canUse num : "<<rc_pool.getCanUseNum()<<endl;
    rc_pool.getConnect();
    
    //2
    cout<<"used num : "<<rc_pool.getUsedCount()<<endl;
    cout<<"canUse num : "<<rc_pool.getCanUseNum()<<endl;
    
    redisContext* context = rc_pool.getConnect();
    if(context == NULL)
        exit(0);
    Redis r1(context);
    r1.set("hello", "hi");
    cout<<r1.get("hello")<<endl;
    r1.del("hello");
    rc_pool.releaseConnect(context);//回收

    //3
    cout<<"used num : "<<rc_pool.getUsedCount()<<endl;
    cout<<"canUse num : "<<rc_pool.getCanUseNum()<<endl;
    context = rc_pool.getConnect();
    if(!rc_pool.isUseful(context))
    {
        cout<<"[ERROR] context is not in use "<<__func__<<__LINE__<<endl;
    }
    Redis redis(context);//初始化，这种方式会自动禁用disconnect
    redis.set("str", "hello");
    string v;
    v = redis.get("str");
    cout<<"get key "<<v<<endl;
    redis.del("str");
    redis.disconnect();//这句话无效
    //rc_pool.releaseConnect(context);//回收
    
    //4
    cout<<"used num : "<<rc_pool.getUsedCount()<<endl;
    cout<<"canUse num : "<<rc_pool.getCanUseNum()<<endl;
    context = rc_pool.getConnect();    
    if(context==NULL)
        cout<<"no context"<<endl;
    Redis redis1(context);
    cout<<redis1.get("str")<<endl;

    rc_pool.releaseConnect(context);
    rc_pool.releaseConnect(context);//重复回收
    
    //5
    cout<<"used num : "<<rc_pool.getUsedCount()<<endl;
    cout<<"canUse num : "<<rc_pool.getCanUseNum()<<endl;
    vector<string> vs;
    redis.keys("*",vs);
    //for(;;);
}

// Assembly:
pushq %rbx
subq $0x280, %rsp            # imm = 0x280
leaq 0xd879(%rip), %rsi      # 0x11004
leaq 0x1f8(%rsp), %rdi
leaq 0x140(%rsp), %rdx
callq 0x3120
leaq 0xd867(%rip), %rsi      # 0x1100e
leaq 0x1d8(%rsp), %rdi
leaq 0x140(%rsp), %rdx
callq 0x3120
leaq 0x140(%rsp), %rdi
callq 0x84f0
leaq 0x140(%rsp), %rdi
pushq $0x64
popq %rsi
leaq 0x1f8(%rsp), %rdx
leaq 0x1d8(%rsp), %r8
movl $0x18eb, %ecx           # imm = 0x18EB
callq 0x85b0
testb %al, %al
je 0x3ddd
movq 0x137db(%rip), %rdi     # 0x16fd8
leaq 0xd827(%rip), %rsi      # 0x1102b
callq 0x3330
movl 0x144(%rsp), %esi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3180
movq 0x137b1(%rip), %rdi     # 0x16fd8
leaq 0xd809(%rip), %rsi      # 0x11037
callq 0x3330
movl 0x1a0(%rsp), %esi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3180
leaq 0x140(%rsp), %rdi
callq 0x8806
movq 0x1377a(%rip), %rdi     # 0x16fd8
leaq 0xd7c6(%rip), %rsi      # 0x1102b
callq 0x3330
movl 0x144(%rsp), %esi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3180
movq 0x13750(%rip), %rdi     # 0x16fd8
leaq 0xd7a8(%rip), %rsi      # 0x11037
callq 0x3330
movl 0x1a0(%rsp), %esi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3180
leaq 0x140(%rsp), %rdi
callq 0x8806
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x3df8
leaq 0x218(%rsp), %rdi
movq %rax, %rsi
callq 0x4004
leaq 0xd768(%rip), %rsi      # 0x11045
leaq 0xd8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x3120
leaq 0xd755(%rip), %rsi      # 0x1104b
leaq 0x70(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x3120
leaq 0x218(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x5240
leaq 0x70(%rsp), %rdi
callq 0x3160
leaq 0xd8(%rsp), %rdi
callq 0x3160
leaq 0xd708(%rip), %rsi      # 0x11045
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x3120
leaq 0xd8(%rsp), %rdi
leaq 0x218(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x533c
movq 0x1366b(%rip), %rdi     # 0x16fd8
leaq 0xd8(%rsp), %rsi
callq 0x3300
movq %rax, %rdi
callq 0x3180
leaq 0xd8(%rsp), %rdi
callq 0x3160
leaq 0x70(%rsp), %rdi
callq 0x3160
leaq 0xd6a5(%rip), %rsi      # 0x11045
leaq 0xd8(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x3120
leaq 0x218(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x43d6
leaq 0xd8(%rsp), %rdi
callq 0x3160
movq 0x8(%rsp), %rsi
leaq 0x140(%rsp), %rdi
callq 0x88ae
movq 0x135eb(%rip), %rdi     # 0x16fd8
leaq 0xd637(%rip), %rsi      # 0x1102b
callq 0x3330
movl 0x144(%rsp), %esi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3180
movq 0x135c1(%rip), %rdi     # 0x16fd8
leaq 0xd619(%rip), %rsi      # 0x11037
callq 0x3330
movl 0x1a0(%rsp), %esi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3180
leaq 0x140(%rsp), %rdi
callq 0x8806
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x140(%rsp), %rdi
callq 0x894e
testb %al, %al
jne 0x3a95
movq 0x13571(%rip), %rdi     # 0x16fd8
leaq 0xd5e0(%rip), %rsi      # 0x1104e
callq 0x3330
leaq 0xd5f3(%rip), %rsi      # 0x1106d
movq %rax, %rdi
callq 0x3330
pushq $0x32
popq %rsi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3180
movq 0x8(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x4004
leaq 0xd5c4(%rip), %rsi      # 0x11072
leaq 0x70(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x3120
leaq 0xd581(%rip), %rsi      # 0x11045
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3120
leaq 0xd8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x5240
leaq 0x50(%rsp), %rdi
callq 0x3160
leaq 0x70(%rsp), %rdi
callq 0x3160
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xd55c(%rip), %rsi      # 0x11072
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3120
leaq 0x70(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x533c
leaq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rbx
movq %rbx, %rsi
callq 0x33d0
movq %rbx, %rdi
callq 0x3160
leaq 0x10(%rsp), %rdi
callq 0x3160
movq 0x13471(%rip), %rdi     # 0x16fd8
leaq 0xd508(%rip), %rsi      # 0x11076
callq 0x3330
leaq 0x50(%rsp), %rsi
movq %rax, %rdi
callq 0x3300
movq %rax, %rdi
callq 0x3180
leaq 0xd4e3(%rip), %rsi      # 0x11072
leaq 0x70(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x3120
leaq 0xd8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x43d6
leaq 0x70(%rsp), %rdi
callq 0x3160
leaq 0xd8(%rsp), %rdi
callq 0x438c
movq 0x1340a(%rip), %rdi     # 0x16fd8
leaq 0xd456(%rip), %rsi      # 0x1102b
callq 0x3330
movl 0x144(%rsp), %esi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3180
movq 0x133e0(%rip), %rdi     # 0x16fd8
leaq 0xd438(%rip), %rsi      # 0x11037
callq 0x3330
movl 0x1a0(%rsp), %esi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3180
leaq 0x140(%rsp), %rdi
callq 0x8806
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x3c52
movq 0x1339f(%rip), %rdi     # 0x16fd8
leaq 0xd43f(%rip), %rsi      # 0x1107f
callq 0x3330
movq %rax, %rdi
callq 0x3180
movq 0x8(%rsp), %rax
leaq 0x70(%rsp), %rdi
movq %rax, %rsi
callq 0x4004
leaq 0xd40c(%rip), %rsi      # 0x11072
leaq 0x30(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3120
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x533c
movq 0x13348(%rip), %rdi     # 0x16fd8
leaq 0x10(%rsp), %rsi
callq 0x3300
movq %rax, %rdi
callq 0x3180
leaq 0x10(%rsp), %rdi
callq 0x3160
leaq 0x30(%rsp), %rdi
callq 0x3160
movq 0x8(%rsp), %rsi
leaq 0x140(%rsp), %rdi
callq 0x88ae
movq 0x8(%rsp), %rsi
leaq 0x140(%rsp), %rdi
callq 0x88ae
movq 0x132f7(%rip), %rdi     # 0x16fd8
leaq 0xd343(%rip), %rsi      # 0x1102b
callq 0x3330
movl 0x144(%rsp), %esi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3180
movq 0x132cd(%rip), %rdi     # 0x16fd8
leaq 0xd325(%rip), %rsi      # 0x11037
callq 0x3330
movl 0x1a0(%rsp), %esi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3180
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
leaq 0xd347(%rip), %rsi      # 0x1108a
leaq 0x10(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3120
leaq 0xd8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x47d8
leaq 0x10(%rsp), %rdi
callq 0x3160
leaq 0x30(%rsp), %rdi
callq 0x3f6c
leaq 0x70(%rsp), %rdi
callq 0x4038
leaq 0x50(%rsp), %rdi
callq 0x3160
leaq 0xd8(%rsp), %rdi
callq 0x4038
leaq 0x218(%rsp), %rdi
callq 0x4038
leaq 0x140(%rsp), %rdi
callq 0x852e
leaq 0x1d8(%rsp), %rdi
callq 0x3160
leaq 0x1f8(%rsp), %rdi
callq 0x3160
xorl %eax, %eax
addq $0x280, %rsp            # imm = 0x280
popq %rbx
retq
movq 0x131f4(%rip), %rdi     # 0x16fd8
leaq 0xd22a(%rip), %rsi      # 0x11015
callq 0x3330
movq %rax, %rdi
callq 0x3180
xorl %edi, %edi
callq 0x33c0
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3160
jmp 0x3e11
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3f6c
jmp 0x3eff
movq %rax, %rbx
jmp 0x3ed4
jmp 0x3efc
jmp 0x3f10
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
jmp 0x3e49
jmp 0x3f10
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3160
jmp 0x3f13
jmp 0x3f10
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x3160
jmp 0x3e6a
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
jmp 0x3f18
movq %rax, %rbx
jmp 0x3f1d
jmp 0x3f0b
jmp 0x3e9e
jmp 0x3f0b
movq %rax, %rbx
jmp 0x3ef0
jmp 0x3f0b
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x3160
jmp 0x3ea1
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
jmp 0x3ef5
jmp 0x3f0b
jmp 0x3f39
jmp 0x3f39
movq %rax, %rbx
jmp 0x3f49
movq %rax, %rbx
jmp 0x3f56
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3160
leaq 0x30(%rsp), %rdi
callq 0x3160
jmp 0x3eff
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x3160
leaq 0x70(%rsp), %rdi
callq 0x3160
jmp 0x3f2a
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x4038
jmp 0x3f13
movq %rax, %rbx
jmp 0x3f2a
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x3160
leaq 0xd8(%rsp), %rdi
callq 0x4038
leaq 0x218(%rsp), %rdi
callq 0x4038
jmp 0x3f3c
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x852e
leaq 0x1d8(%rsp), %rdi
callq 0x3160
leaq 0x1f8(%rsp), %rdi
callq 0x3160
movq %rbx, %rdi
callq 0x3540
nop