Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

IO Multiplexing of Redis

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. IO reuse function of linux

IO operations with multiple descriptors in the same thread can be performed concurrently and sequentially.

Epoll provides only three functions:

Int epoll_create (int size); # create an epoll handle

Int epoll_ctl (int epfd, int op, int fd, struct epoll_event * event)

Associate listening events with epool handles (you can add, delete, and modify associations through the op parameter)

The first parameter, epfd, is the return value of epoll_create ()

The second parameter, op, indicates the association: EPOLL_CTL_ADD (add) EPOLL_CTL_MOD (change) EPOLL_CTL_DEL (delete)

The third parameter, fd, is the fd to be listened to.

The fourth parameter, event, tells the kernel what specific events to listen for: EPOLLIN (readable) EPOLLOUT (writable) EPOLLPRI (emergency readable) EPOLLERR (error) EPOLLHUP (hang up) EPOLLET (trigger mode ET or LT) EPOLLONESHOT (listen only once)

You can set the callback function corresponding to the event here.

Int epoll_wait (int epfd, struct epoll_event * events, int maxevents, int timeout)

If no listening event is generated in epoll_ctl, it will block here until the listening event occurs, or until the timeout occurs.

If there is an event listening in the epoll_ctl, the specific event handling callback function is executed.

Epoll ensures that each fd is copied only once throughout the process, from kernel space to user space.

2. IO Multiplexing of redis

Redis uses epoll to achieve IO multiplexing, putting connection information and events into a queue, then putting them into a file event dispatcher, which distributes events to event handlers.

Event handlers handle different events.

Main-> aeMain-> while {aeProcessEvents-> aeApiPoll-> epoll_wait}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report