// File: /workspace/github_c_makefile_star2_O3/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 0x69c22(%rip), %rbx     # 0xc9fa8
testl %edi, 0x7b8(%rbx)
je 0x604c2
movl %ecx, %ebp
movq %rdx, %r13
movq %rsi, %r14
movq %rsi, %rdi
callq 0x1f4f0
movq %r14, %rdi
movq %rax, %rsi
callq 0x3068f
movq %rax, %r14
movl 0x7b8(%rbx), %eax
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testb $0x1, %al
je 0x6043b
leaq 0x3fc2f(%rip), %rdi     # 0x9fff6
movl $0xb, %esi
callq 0x283f4
movq %rax, %r12
movslq %ebp, %rdx
movq %rsp, %rdi
movl $0x18, %esi
callq 0x300c7
movl %eax, %r15d
movslq %eax, %rdx
movq %r12, %rdi
movq %rsp, %rsi
callq 0x28689
leaq 0x3fc06(%rip), %rsi     # 0xa0002
movl $0x3, %edx
movq %rax, %rdi
callq 0x28689
movq 0x8(%r13), %rsi
movq %rax, %rdi
callq 0x2873e
xorl %edi, %edi
movq %rax, %rsi
callq 0x3059c
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x4b702
movq %r12, %rdi
callq 0x30b0c
movl 0x7b8(%rbx), %eax
testb $0x2, %al
je 0x604ba
leaq 0x3fbc0(%rip), %rdi     # 0xa0006
movl $0xb, %esi
callq 0x283f4
movq %rax, %r12
cmpl $-0x1, %r15d
jne 0x6046c
movslq %ebp, %rdx
movq %rsp, %rdi
movl $0x18, %esi
callq 0x300c7
movl %eax, %r15d
movslq %r15d, %rdx
movq %rsp, %rsi
movq %r12, %rdi
callq 0x28689
leaq 0x3fb81(%rip), %rsi     # 0xa0002
movl $0x3, %edx
movq %rax, %rdi
callq 0x28689
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x2873e
xorl %edi, %edi
movq %rax, %rsi
callq 0x3059c
movq %rax, %r15
movq %rax, %rdi
movq %r13, %rsi
callq 0x4b702
movq %r15, %rdi
callq 0x30b0c
movq %r14, %rdi
callq 0x30b0c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)