#1475·predis

Support basic events for connection and commands.

Author: GrzegorzDrozdCreated Aug 29, 2024Updated Mar 25, 2025
Labelsfeature

Is your feature request related to a problem? Please describe. I would like to instrument my application. It uses redis and predis heavily with cache, mutexes and pub/sub. I would like to add instrumentation like new relic or sentry traces. I would like to know how long it takes to connect and to send specific commands. To achieve this it would be great if I could add psr compatible event dispatcher to predis. Then, when specific events occur I could add instrumentation in the event handler.

Describe the solution you'd like

  1. add new client option: 'event_dispatcher'
  2. add a call to event_dispatcher::dispatch() to connect/disconnect
  3. add a call to event_dispatcher::dispatch() to __call before and after executing a command to handle most of the commands
  4. add a call to event_dispatcher::dispatch() executeCommand, transaction, pipeline and onErrorResponse to handle rest of the commands.

Describe alternatives you've considered Manually wrapping every command but that would be cumbersome and would take a lot of time.

I would be willing to try to implement this if the team is open for this.