1

Setup

  1. PHP 8.2
  2. Redis 5.3.7
  3. VSCode 1.79.0
  4. Intelephense 1.9.5

Problem

When using Redis::subscribe I get an error, because according to the hover subscribe only takes strings as parameters. But it should be (array, callable). Not sure where the root of this bug lays. With redis, intelephense, vscode...?

enter image description here

On github in phpredis/redis.stub.php it says

/**
 * Subscribe to one or more Redis pubsub channels.
 *
 * @param array    $channels One or more channel names.
 * @param callable $cb       The callback PhpRedis will invoke when we receive a message
 *                           from one of the subscribed channels.
 *
 * @return bool True on success, false on faiilure.  Note that this command will block the
 *              client in a subscribe loop, waiting for messages to arrive.
 *
 * @see https://redis.io/commands/subscribe
 *
 * @example
 * $redis = new Redis(['host' => 'localhost']);
 *
 * $redis->subscribe(['channel-1', 'channel-2'], function ($redis, $channel, $message) {
 *     echo "[$channel]: $message\n";
 *
 *     // Unsubscribe from the message channel when we read 'quit'
 *     if ($message == 'quit') {
 *         echo "Unsubscribing from '$channel'\n";
 *         $redis->unsubscribe([$channel]);
 *     }
 * });
 *
 * // Once we read 'quit' from both channel-1 and channel-2 the subscribe loop will be
 * // broken and this command will execute.
 * echo "Subscribe loop ended\n";
 */
public function subscribe(array $channels, callable $cb): bool;

0 Answers0