Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add finalizer support in async API #1173

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Commits on Jul 19, 2023

  1. Rewrite async callback queue (push/shift) to not do allocations

    The callback queue in the changed so that each callback is allocated once and
    freed once. The operations "push" and "shift" don't copy the callback struct
    between heap and stack, but instead they and just set the 'next' pointer to link
    callbacks into a list, without doing any allocations. For pubsub channels, one
    callback can be mapped to multiple channels, and they can be unsubscribed
    independently, so we use a reference counter to keep track of references to a
    callback.
    
    This prepares for adding finalizer support and to be sure it is called only
    once, when the callback is freed.
    
    The way hiredis kept tack of 'pubsub mode' using `pending_subs` and
    `unsubscribe_sent` was flawed. It couldn't handle multiple pending subscribe
    commands with an overlapping but different set of channels and it couldn't
    handle an error reply to a SUBSCRIBE or UNSUBSCRIBE command. Now we change this
    so that all commands, even SUBSCRIBE and UNSUBSCRIBE, are added to the reply
    queue and the 'subscribe' and 'unsubscribe' replies are matched against them in
    the queue. The channel-to-callback dicts are updated when a 'subscribe' or
    'unsubscribe' reply is received, confirming that the client has subscribed or
    unsubscribed to a channel, rather than when the command is sent. This change
    makes it possible to handle an error reply for a pubsub command.
    
    With this change, there is no need to keep a different replies queue for
    subscribe commands and regular commands. All are added to the same replies
    queue.
    zuiderkwast committed Jul 19, 2023
    Configuration menu
    Copy the full SHA
    342cb92 View commit details
    Browse the repository at this point in the history
  2. Add finalizer support to async Redis client

    * For each time redisAsyncCommandWithFinalizer or one of its variants has been
      called with a finalizer, the finalizer will be called exactly once.
    * The finalizer is called when a callback (even if the callback function is
      NULL) is no longer associated with any command or pubsub channel or pattern.
    * The finalizer is called after the last call to the callback. The callback is
      never called after the finalizer has been called.
    
    New async API functions added:
    
    * redisvAsyncCommandWithFinalizer
    * redisAsyncCommandWithFinalizer
    * redisAsyncCommandArgvWithFinalizer
    * redisAsyncFormattedCommandWithFinalizer
    
    Co-Authored-By: Tudor Bosman <[email protected]>
    zuiderkwast and tudor committed Jul 19, 2023
    Configuration menu
    Copy the full SHA
    1dff7b4 View commit details
    Browse the repository at this point in the history
  3. Add example-libevent-pubsub

    Co-Authored-By: Tudor Bosman <[email protected]>
    zuiderkwast and tudor committed Jul 19, 2023
    Configuration menu
    Copy the full SHA
    5468136 View commit details
    Browse the repository at this point in the history

Commits on Jul 20, 2023

  1. Implement RESET in async API: Cancel subscriptions and monitor mode

    Additionally, accept commands in monitor mode. (For example the RESET
    command, but also other commands.)
    
    Apart from being useful but itself, this change makes the async API's
    reply queue stay in sync (mapping each reply to the callback given
    when the command was sent) when bombed with random commands (fuzzing).
    zuiderkwast committed Jul 20, 2023
    Configuration menu
    Copy the full SHA
    41cf219 View commit details
    Browse the repository at this point in the history

Commits on Jul 21, 2023

  1. Configuration menu
    Copy the full SHA
    17c391b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    cbe49dd View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    7081c21 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    7f8a1bb View commit details
    Browse the repository at this point in the history

Commits on Aug 23, 2023

  1. Configuration menu
    Copy the full SHA
    63968e9 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    cb6fbbf View commit details
    Browse the repository at this point in the history
  3. Fixup: Spelling

    zuiderkwast committed Aug 23, 2023
    Configuration menu
    Copy the full SHA
    401053a View commit details
    Browse the repository at this point in the history
  4. Fixup: Spelling again

    zuiderkwast committed Aug 23, 2023
    Configuration menu
    Copy the full SHA
    27d36f4 View commit details
    Browse the repository at this point in the history