// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
leaq 0x6bb0b(%rip), %r15     # 0xc6fa8
testl %edi, 0x7b8(%r15)
je 0x5b5df
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r14
movq %rsi, %rdi
callq 0x1f4f0
movq %r14, %rdi
movq %rax, %rsi
callq 0x2ea81
movq %rax, %r14
movl 0x7b8(%r15), %eax
movslq %ebp, %rbp
testb $0x1, %al
movq %rbp, 0x8(%rsp)
jne 0x5b4e0
pushq $-0x1
popq %rbp
jmp 0x5b55a
leaq 0x3aa83(%rip), %rdi     # 0x95f6a
pushq $0xb
popq %rsi
callq 0x27158
movq %rax, %r12
leaq 0x10(%rsp), %r13
pushq $0x18
popq %rsi
movq %r13, %rdi
movq %rbp, %rdx
callq 0x2e511
movl %eax, %ebp
movslq %eax, %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x2736d
leaq 0x3aa5a(%rip), %rsi     # 0x95f76
pushq $0x3
popq %rdx
movq %rax, %rdi
callq 0x2736d
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x273e6
xorl %edi, %edi
movq %rax, %rsi
callq 0x2e9b4
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x47f05
movq %r12, %rdi
callq 0x2ee1f
movl 0x7b8(%r15), %eax
testb $0x2, %al
je 0x5b5d7
leaq 0x3aa15(%rip), %rdi     # 0x95f7a
pushq $0xb
popq %rsi
callq 0x27158
movq %rax, %r12
cmpl $-0x1, %ebp
jne 0x5b589
leaq 0x10(%rsp), %rdi
pushq $0x18
popq %rsi
movq 0x8(%rsp), %rdx
callq 0x2e511
movl %eax, %ebp
movslq %ebp, %rdx
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x2736d
leaq 0x3a9d6(%rip), %rsi     # 0x95f76
pushq $0x3
popq %rdx
movq %rax, %rdi
callq 0x2736d
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x273e6
xorl %edi, %edi
movq %rax, %rsi
callq 0x2e9b4
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x47f05
movq %r15, %rdi
callq 0x2ee1f
movq %r14, %rdi
callq 0x2ee1f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop