// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/notify.c
// Function: notifyKeyspaceEvent
void notifyKeyspaceEvent(int type, char *event, robj *key, int dbid) {
    sds chan;
    robj *chanobj, *eventobj;
    int len = -1;
    char buf[24];

    /* If notifications for this class of events are off, return ASAP. */
    // 如果服务器配置为不发送 type 类型的通知，那么直接返回
    if (!(server.notify_keyspace_events & type)) return;

    // 事件的名字
    eventobj = createStringObject(event,strlen(event));

    /* __keyspace@<db>__:<key> <event> notifications. */
    // 发送键空间通知
    if (server.notify_keyspace_events & REDIS_NOTIFY_KEYSPACE) {

        // 构建频道对象
        chan = sdsnewlen("__keyspace@",11);
        len = ll2string(buf,sizeof(buf),dbid);
        chan = sdscatlen(chan, buf, len);
        chan = sdscatlen(chan, "__:", 3);
        chan = sdscatsds(chan, key->ptr);

        chanobj = createObject(REDIS_STRING, chan);

        // 通过 publish 命令发送通知
        pubsubPublishMessage(chanobj, eventobj);

        // 释放频道对象
        decrRefCount(chanobj);
    }

    /* __keyevente@<db>__:<event> <key> notifications. */
    // 发送键事件通知
    if (server.notify_keyspace_events & REDIS_NOTIFY_KEYEVENT) {

        // 构建频道对象
        chan = sdsnewlen("__keyevent@",11);
        // 如果在前面发送键空间通知的时候计算了 len ，那么它就不会是 -1
        // 这可以避免计算两次 buf 的长度
        if (len == -1) len = ll2string(buf,sizeof(buf),dbid);
        chan = sdscatlen(chan, buf, len);
        chan = sdscatlen(chan, "__:", 3);
        chan = sdscatsds(chan, eventobj->ptr);

        chanobj = createObject(REDIS_STRING, chan);

        // 通过 publish 命令发送通知
        pubsubPublishMessage(chanobj, key);

        // 释放频道对象
        decrRefCount(chanobj);
    }

    // 释放事件对象
    decrRefCount(eventobj);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x696de(%rip), %rbx     # 0xc9fa8
testl %edi, 0x7b8(%rbx)
je 0x60a04
movl %ecx, %ebp
movq %rdx, %r13
movq %rsi, %r14
movq %rsi, %rdi
callq 0x1f4f0
movq %r14, %rdi
movq %rax, %rsi
callq 0x303b7
movq %rax, %r14
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testb $0x1, 0x7b8(%rbx)
je 0x60978
leaq 0x3f67c(%rip), %rdi     # 0x9ff86
movl $0xb, %esi
callq 0x28148
movq %rax, %r12
movslq %ebp, %rdx
movq %rsp, %rdi
movl $0x18, %esi
callq 0x2fe12
movl %eax, %r15d
movslq %eax, %rdx
movq %r12, %rdi
movq %rsp, %rsi
callq 0x28380
leaq 0x3f653(%rip), %rsi     # 0x9ff92
movl $0x3, %edx
movq %rax, %rdi
callq 0x28380
movq 0x8(%r13), %rsi
movq %rax, %rdi
callq 0x2843c
xorl %edi, %edi
movq %rax, %rsi
callq 0x302c4
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x4bd12
movq %r12, %rdi
callq 0x30834
testb $0x2, 0x7b8(%rbx)
je 0x609fc
leaq 0x3f60e(%rip), %rdi     # 0x9ff96
movl $0xb, %esi
callq 0x28148
movq %rax, %r12
cmpl $-0x1, %r15d
jne 0x609ae
movslq %ebp, %rdx
movq %rsp, %rdi
movl $0x18, %esi
callq 0x2fe12
movl %eax, %r15d
movslq %r15d, %rdx
movq %rsp, %rsi
movq %r12, %rdi
callq 0x28380
leaq 0x3f5cf(%rip), %rsi     # 0x9ff92
movl $0x3, %edx
movq %rax, %rdi
callq 0x28380
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x2843c
xorl %edi, %edi
movq %rax, %rsi
callq 0x302c4
movq %rax, %r15
movq %rax, %rdi
movq %r13, %rsi
callq 0x4bd12
movq %r15, %rdi
callq 0x30834
movq %r14, %rdi
callq 0x30834
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop