一、什麼是redis
redis 是一個開源的、內存級的鍵值對,可作爲緩存,消息隊列,數據庫。支持多種數據結構,比如string,hash, list,set,sorted set。
二、整體架構
事件驅動、單進程,單線程命令處理
int main(int argc, char **argv) {
...
aeMain(server.el);
...
return 0;
}
void aeMain(aeEventLoop *eventLoop) {
eventLoop->stop = 0;
while (!eventLoop->stop) {
aeProcessEvents(eventLoop, AE_ALL_EVENTS|
AE_CALL_BEFORE_SLEEP|
AE_CALL_AFTER_SLEEP);
}
}
int aeProcessEvents(aeEventLoop *eventLoop, int flags)
{
...
numevents = aeApiPoll(eventLoop, tvp);
...
for (j = 0; j < numevents; j++) {
...
if (mask & AE_READABLE) {
fe->rfileProc(eventLoop,fd,fe->clientData,mask);
...
}
if (mask & AE_WRITABLE) {
if (!fired || fe->wfileProc != fe->rfileProc) {
fe->wfileProc(eventLoop,fd,fe->clientData,mask);
...
}
}
...
}
..
}