// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/db.c
// Function: expireGenericCommand
void expireGenericCommand(redisClient *c, long long basetime, int unit) {
    robj *key = c->argv[1], *param = c->argv[2];
    long long when; /* unix time in milliseconds when the key will expire. */

    // 取出 when 参数
    if (getLongLongFromObjectOrReply(c, param, &when, NULL) != REDIS_OK)
        return;

    // 如果传入的过期时间是以秒为单位的，那么将它转换为毫秒
    if (unit == UNIT_SECONDS) when *= 1000;
    when += basetime;

    /* No key, return zero. */
    // 取出键
    if (lookupKeyRead(c->db,key) == NULL) {
        addReply(c,shared.czero);
        return;
    }

    /* EXPIRE with negative TTL, or EXPIREAT with a timestamp into the past
     * should never be executed as a DEL when load the AOF or in the context
     * of a slave instance.
     *
     * 在载入数据时，或者服务器为附属节点时，
     * 即使 EXPIRE 的 TTL 为负数，或者 EXPIREAT 提供的时间戳已经过期，
     * 服务器也不会主动删除这个键，而是等待主节点发来显式的 DEL 命令。
     *
     * Instead we take the other branch of the IF statement setting an expire
     * (possibly in the past) and wait for an explicit DEL from the master. 
     *
     * 程序会继续将（一个可能已经过期的 TTL）设置为键的过期时间，
     * 并且等待主节点发来 DEL 命令。
     */
    if (when <= mstime() && !server.loading && !server.masterhost) {

        // when 提供的时间已经过期，服务器为主节点，并且没在载入数据

        robj *aux;

        redisAssertWithInfo(c,key,dbDelete(c->db,key));
        server.dirty++;

        /* Replicate/AOF this as an explicit DEL. */
        // 传播 DEL 命令
        aux = createStringObject("DEL",3);

        rewriteClientCommandVector(c,2,aux,key);
        decrRefCount(aux);

        signalModifiedKey(c->db,key);
        notifyKeyspaceEvent(REDIS_NOTIFY_GENERIC,"del",key,c->db->id);

        addReply(c, shared.cone);

        return;
    } else {

        // 设置键的过期时间
        // 如果服务器为附属节点，或者服务器正在载入，
        // 那么这个 when 有可能已经过期的
        setExpire(c->db,key,when);

        addReply(c,shared.cone);

        signalModifiedKey(c->db,key);
        notifyKeyspaceEvent(REDIS_NOTIFY_GENERIC,"expire",key,c->db->id);

        server.dirty++;

        return;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movq 0x8(%rax), %r14
movq 0x10(%rax), %rsi
leaq 0x8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x31355
testl %eax, %eax
jne 0x32e60
movq 0x8(%rsp), %rax
imulq $0x3e8, %rax, %rcx      # imm = 0x3E8
testl %ebp, %ebp
cmovneq %rax, %rcx
addq %r15, %rcx
movq %rcx, 0x8(%rsp)
movq 0x8(%rbx), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x31673
movq %r15, %rdi
movq %r14, %rsi
callq 0x315f8
xorl %ecx, %ecx
testq %rax, %rax
sete %cl
leaq 0x9726b(%rip), %r15     # 0xc9fa8
incq 0x368(%r15,%rcx,8)
testq %rax, %rax
je 0x32dfd
movq 0x8(%rsp), %r12
callq 0x23461
movq 0x8(%rbx), %rdi
cmpq %rax, %r12
jg 0x32e12
cmpl $0x0, 0x2f0(%r15)
jne 0x32e12
cmpq $0x0, 0x650(%r15)
jne 0x32e12
movq %r14, %rsi
callq 0x31a36
testl %eax, %eax
je 0x32e6d
incq 0x560(%r15)
leaq 0x61f7e(%rip), %rdi     # 0x94d1d
movl $0x3, %esi
callq 0x3068f
movq %rax, %r15
movq %rbx, %rdi
movl $0x2, %esi
movq %rax, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x2f870
movq %r15, %rdi
callq 0x30b0c
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x4c221
movq 0x8(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x616fa(%rip), %rsi     # 0x944dd
movl $0x4, %edi
movq %r14, %rdx
callq 0x60371
leaq 0x97a09(%rip), %rax     # 0xca800
movq 0x28(%rax), %rsi
jmp 0x32e08
leaq 0x979fc(%rip), %rax     # 0xca800
movq 0x20(%rax), %rsi
movq %rbx, %rdi
callq 0x2d97c
jmp 0x32e60
movq 0x8(%rsp), %rdx
movq %r14, %rsi
callq 0x32a5e
leaq 0x979da(%rip), %rax     # 0xca800
movq 0x28(%rax), %rsi
movq %rbx, %rdi
callq 0x2d97c
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x4c221
movq 0x8(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x684b7(%rip), %rsi     # 0x9b303
movl $0x4, %edi
movq %r14, %rdx
callq 0x60371
incq 0x560(%r15)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x648ab(%rip), %rdx     # 0x9771f
leaq 0x65c1e(%rip), %rcx     # 0x98a99
movq %rbx, %rdi
movq %r14, %rsi
movl $0x50a, %r8d            # imm = 0x50A
callq 0x4d277
movl $0x1, %edi
callq 0x1f3b0