• Meir Shpilraien (Spielrein)'s avatar
    Before evicted and before expired server events are not executed inside an execution unit. (#12733) · 0ffb9d2e
    Meir Shpilraien (Spielrein) authored
    Redis 7.2 (#9406) introduced a new modules event, `RedisModuleEvent_Key`.
    This new event allows the module to read the key data just before it is removed
    from the database (either deleted, expired, evicted, or overwritten).
    
    When the key is removed from the database, either by active expire or eviction.
    The new event was not called as part of an execution unit. This can cause an
    issue if the module registers a post notification job inside the event. This job will
    not be executed atomically with the expiration/eviction operation and will not
    replicated inside a Multi/Exec. Moreover, the post notification job will be executed
    right after the event where it is still not safe to perform any write operation, this will
    violate the promise that post notification job will be called atomically with the
    operation that triggered it and **only when it is safe to write**.
    
    This PR fixes the issue by wrapping each expiration/eviction of a key with an execution
    unit. This makes sure the entire operation will run atomically and all the post notification
    jobs will be executed at the end where it is safe to write.
    
    Tests were modified to verify the fix.
    0ffb9d2e
postnotifications.tcl 6.84 KB