Home > Database > Redis > How to use lazy deletion Lazy free in Redis

How to use lazy deletion Lazy free in Redis

WBOY
Release: 2023-05-26 23:37:04
forward
1932 people have browsed it

Use lazy deletion Lazy free

When the key expires or the DEL delete command is used, Redis will not only remove the object from the global hash table, but also release the memory allocated by the object. When a big key is encountered, releasing memory will cause the main thread to block.

To this end, Redis 4.0 introduced the UNLINK command, which puts the operation of releasing object memory into the bio background thread for execution. This effectively reduces main thread blocking.

Redis 6.0 goes a step further and introduces Lazy-free related configurations. When the configuration is enabled, the "release object" operation will be "executed asynchronously" within the key expiration and DEL commands.

void delCommand(client *c) {
    delGenericCommand(c,server.lazyfree_lazy_user_del);}void delGenericCommand(client *c, int lazy) {
    int numdel = 0, j;

    for (j = 1; j < c->argc; j++) {
        expireIfNeeded(c->db,c->argv[j]);
        // 开启 lazy free 则使用异步删除
        int deleted = lazy ? dbAsyncDelete(c->db,c->argv[j]) :
                              dbSyncDelete(c->db,c->argv[j]);
        ...
    }}
Copy after login

It is recommended to upgrade to at least Redis 6 and turn on Lazy-free.

The above is the detailed content of How to use lazy deletion Lazy free in Redis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template