// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/db.c
// Function: expireIfNeeded
int expireIfNeeded(redisDb *db, robj *key) {

    // 取出键的过期时间
    mstime_t when = getExpire(db,key);
    mstime_t now;

    // 没有过期时间
    if (when < 0) return 0; /* No expire for this key */

    /* Don't expire anything while loading. It will be done later. */
    // 如果服务器正在进行载入，那么不进行任何过期检查
    if (server.loading) return 0;

    /* If we are in the context of a Lua script, we claim that time is
     * blocked to when the Lua script started. This way a key can expire
     * only the first time it is accessed and not in the middle of the
     * script execution, making propagation to slaves / AOF consistent.
     * See issue #1525 on Github for more information. */
    now = server.lua_caller ? server.lua_time_start : mstime();

    /* If we are running in the context of a slave, return ASAP:
     * the slave key expiration is controlled by the master that will
     * send us synthesized DEL operations for expired keys.
     *
     * Still we try to return the right information to the caller, 
     * that is, 0 if we think the key should be still valid, 1 if
     * we think the key is expired at this time. */
    // 当服务器运行在 replication 模式时
    // 附属节点并不主动删除 key
    // 它只返回一个逻辑上正确的返回值
    // 真正的删除操作要等待主节点发来删除命令时才执行
    // 从而保证数据的同步
    if (server.masterhost != NULL) return now > when;

    // 运行到这里，表示键带有过期时间，并且服务器为主节点

    /* Return when this key has not expired */
    // 如果未过期，返回 0
    if (now <= when) return 0;

    /* Delete the key */
    server.stat_expiredkeys++;

    // 向 AOF 文件和附属节点传播过期信息
    propagateExpire(db,key);

    // 发送事件通知
    notifyKeyspaceEvent(REDIS_NOTIFY_EXPIRED,
        "expired",key,db->id);

    // 将过期键从数据库中删除
    return dbDelete(db,key);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3dce0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jge 0x3bf94
movl $0x0, -0x4(%rbp)
jmp 0x3c078
leaq 0xd795d(%rip), %rax     # 0x1138f8
cmpl $0x0, 0x2f0(%rax)
je 0x3bfb0
movl $0x0, -0x4(%rbp)
jmp 0x3c078
leaq 0xd7941(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x7f0(%rax)
je 0x3bfd5
leaq 0xd7930(%rip), %rax     # 0x1138f8
movq 0x808(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x3bfde
callq 0x252e0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq 0xd790b(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x650(%rax)
je 0x3c00c
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
setg %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x4(%rbp)
jmp 0x3c078
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jg 0x3c01f
movl $0x0, -0x4(%rbp)
jmp 0x3c078
leaq 0xd78d2(%rip), %rax     # 0x1138f8
movq 0x358(%rax), %rcx
addq $0x1, %rcx
leaq 0xd78c0(%rip), %rax     # 0x1138f8
movq %rcx, 0x358(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3e030
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rax
movl 0x30(%rax), %ecx
movl $0x100, %edi            # imm = 0x100
leaq 0xa26cc(%rip), %rsi     # 0xde72f
callq 0x814a0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3c4f0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)