// File: /workspace/github_c_makefile_star2_O2/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 0x2f617
testl %eax, %eax
jne 0x30ed5
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), %rdi
movq %r14, %rsi
callq 0x2f89e
testq %rax, %rax
je 0x30e74
movq 0x8(%rsp), %r12
callq 0x22843
leaq 0x961d3(%rip), %r15     # 0xc6fa8
movq 0x8(%rbx), %rdi
cmpq %rax, %r12
jg 0x30e89
cmpl $0x0, 0x2f0(%r15)
jne 0x30e89
cmpq $0x0, 0x650(%r15)
jne 0x30e89
movq %r14, %rsi
callq 0x2fc3b
testl %eax, %eax
je 0x30ee2
incq 0x560(%r15)
leaq 0x59ec1(%rip), %rdi     # 0x8acdd
pushq $0x3
popq %rsi
callq 0x2ea81
movq %rax, %r15
pushq $0x2
popq %rsi
movq %rbx, %rdi
movq %rax, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x2dd2e
movq %r15, %rdi
callq 0x2ee1f
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x488d7
movq 0x8(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x59641(%rip), %rsi     # 0x8a49d
pushq $0x4
popq %rdi
movq %r14, %rdx
callq 0x5b488
leaq 0x96992(%rip), %rax     # 0xc7800
movq 0x28(%rax), %rsi
jmp 0x30e7f
leaq 0x96985(%rip), %rax     # 0xc7800
movq 0x20(%rax), %rsi
movq %rbx, %rdi
callq 0x2c10d
jmp 0x30ed5
movq 0x8(%rsp), %rdx
movq %r14, %rsi
callq 0x30b2d
leaq 0x96963(%rip), %rax     # 0xc7800
movq 0x28(%rax), %rsi
movq %rbx, %rdi
callq 0x2c10d
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x488d7
movq 0x8(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x60400(%rip), %rsi     # 0x912c3
pushq $0x4
popq %rdi
movq %r14, %rdx
callq 0x5b488
incq 0x560(%r15)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5c818(%rip), %rdx     # 0x8d701
leaq 0x5db6d(%rip), %rcx     # 0x8ea5d
movq %rbx, %rdi
movq %r14, %rsi
movl $0x50a, %r8d            # imm = 0x50A
callq 0x4980c
pushq $0x1
popq %rdi
callq 0x1f3b0