structredisServer { list *slowlog; /* SLOWLOG list of commands */ longlong slowlog_entry_id; /* SLOWLOG current entry ID */ longlong slowlog_log_slower_than; /* SLOWLOG time limit (to get logged) */ unsignedlong slowlog_max_len; /* SLOWLOG max number of items logged */ }
s = sdscatprintf(s,"... (%lu more bytes)", (unsignedlong) sdslen(argv[j]->ptr) - SLOWLOG_ENTRY_MAX_STRING); se->argv[j] = createObject(OBJ_STRING,s); } elseif (argv[j]->refcount == OBJ_SHARED_REFCOUNT) { se->argv[j] = argv[j]; } else { /* Here we need to duplicate the string objects composing the * argument vector of the command, because those may otherwise * end shared with string objects stored into keys. Having * shared objects between any part of Redis, and the data * structure holding the data, is a problem: FLUSHALL ASYNC * may release the shared string object and create a race. */ se->argv[j] = dupStringObject(argv[j]); } } } // 设置命令的执行时间 se->time = time(NULL); // 设置发生时间 se->duration = duration; se->id = server.slowlog_entry_id++; se->peerid = sdsnew(getClientPeerId(c)); se->cname = c->name ? sdsnew(c->name->ptr) : sdsempty(); return se; }
删除慢查询日志
遍历服务器的慢查询日志,如果存在,则逐条删除。
1 2 3
voidslowlogReset(void) { while (listLength(server.slowlog) > 0) listDelNode(server.slowlog,listLast(server.slowlog));