// File: /workspace/github_c_makefile_star2_O1/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 0x31082
testl %eax, %eax
jne 0x32b03
testl %ebp, %ebp
jne 0x329d0
imulq $0x3e8, 0x8(%rsp), %rax # imm = 0x3E8
movq %rax, 0x8(%rsp)
addq %r15, 0x8(%rsp)
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x3136a
testq %rax, %rax
je 0x32aa0
movq 0x8(%rsp), %r12
callq 0x232a3
leaq 0x975ad(%rip), %r15     # 0xc9fa8
movq 0x8(%rbx), %rdi
cmpq %rax, %r12
jg 0x32ab5
cmpl $0x0, 0x2f0(%r15)
jne 0x32ab5
cmpq $0x0, 0x650(%r15)
jne 0x32ab5
movq %r14, %rsi
callq 0x3174b
testl %eax, %eax
je 0x32b10
incq 0x560(%r15)
leaq 0x6228b(%rip), %rdi     # 0x94ccd
movl $0x3, %esi
callq 0x303b7
movq %rax, %r15
movq %rbx, %rdi
movl $0x2, %esi
movq %rax, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x2f581
movq %r15, %rdi
callq 0x30834
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x4c839
movq 0x8(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x61a07(%rip), %rsi     # 0x9448d
movl $0x4, %edi
movq %r14, %rdx
callq 0x608b5
leaq 0x97d66(%rip), %rax     # 0xca800
movq 0x28(%rax), %rsi
jmp 0x32aab
leaq 0x97d59(%rip), %rax     # 0xca800
movq 0x20(%rax), %rsi
movq %rbx, %rdi
callq 0x2d6f0
jmp 0x32b03
movq 0x8(%rsp), %rdx
movq %r14, %rsi
callq 0x32732
leaq 0x97d37(%rip), %rax     # 0xca800
movq 0x28(%rax), %rsi
movq %rbx, %rdi
callq 0x2d6f0
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x4c839
movq 0x8(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x687d4(%rip), %rsi     # 0x9b2c3
movl $0x4, %edi
movq %r14, %rdx
callq 0x608b5
incq 0x560(%r15)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x64b96(%rip), %rdx     # 0x976ad
leaq 0x65f1f(%rip), %rcx     # 0x98a3d
movq %rbx, %rdi
movq %r14, %rsi
movl $0x50a, %r8d            # imm = 0x50A
callq 0x4d872
movl $0x1, %edi
callq 0x1f3b0