美文网首页
Redis 发布订阅

Redis 发布订阅

作者: 爱折腾的傻小子 | 来源:发表于2020-09-30 09:18 被阅读0次
Publish 将信息发送到指定的频道
  • publish redis命令 PUBLISH channel message
/**
     * Publish messages to channels.
     *
     * Warning: this function will probably change in the future.
     *
     * @param string $channel a channel to publish to
     * @param string $message string
     *
     * @return int Number of clients that received the message
     *
     * @link    https://redis.io/commands/publish
     * @example $redis->publish('chan-1', 'hello, world!'); // send message.
     */
    public function publish($channel, $message)
    {
    }
Subscribe 订阅给定的一个或多个频道的信息
  • subscribe redis命令 SUBSCRIBE channel [channel ...]
/**
     * Subscribe to channels.
     *
     * Warning: this function will probably change in the future.
     *
     * @param string[]     $channels an array of channels to subscribe
     * @param string|array $callback either a string or an array($instance, 'method_name').
     * The callback function receives 3 parameters: the redis instance, the channel name, and the message.
     *
     * @return mixed|null Any non-null return value in the callback will be returned to the caller.
     *
     * @link    https://redis.io/commands/subscribe
     * @example
     * <pre>
     * function f($redis, $chan, $msg) {
     *  switch($chan) {
     *      case 'chan-1':
     *          ...
     *          break;
     *
     *      case 'chan-2':
     *                     ...
     *          break;
     *
     *      case 'chan-2':
     *          ...
     *          break;
     *      }
     * }
     *
     * $redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
     * </pre>
     */
    public function subscribe($channels, $callback)
    {
    }
pSubscribe 订阅一个或多个符合给定模式的频道
  • 每个模式以 * 作为匹配符,比如 it* 匹配所有以 it 开头的频道( it.news 、 it.blog 、 it.tweets 等等)
  • news.* 匹配所有以 news. 开头的频道( news.it 、 news.global.today 等等),诸如此类
/**
     * Subscribe to channels by pattern
     *
     * @param array        $patterns   an array of glob-style patterns to subscribe
     * @param string|array $callback   Either a string or an array with an object and method.
     *                     The callback will get four arguments ($redis, $pattern, $channel, $message)
     * @param mixed        Any non-null return value in the callback will be returned to the caller
     *
     * @link    https://redis.io/commands/psubscribe
     * @example
     * <pre>
     * function psubscribe($redis, $pattern, $chan, $msg) {
     *  echo "Pattern: $pattern\n";
     *  echo "Channel: $chan\n";
     *  echo "Payload: $msg\n";
     * }
     * </pre>
     */
    public function psubscribe($patterns, $callback)
    {
    }
unSubscribe 退订给定的频道
  • unsubscribe redis命令 UNSUBSCRIBE channel [channel ...]
/**
     * Stop listening for messages posted to the given channels.
     *
     * @param array $channels an array of channels to usubscribe
     *
     * @link    https://redis.io/commands/unsubscribe
     */
    public function unsubscribe($channels = null)
    {
    }
pUnsubscribe 退订所有给定模式的频道
  • punsubscribe redis命令 PUNSUBSCRIBE [pattern [pattern ...]]
/**
     * Stop listening for messages posted to the given channels.
     *
     * @param array $patterns   an array of glob-style patterns to unsubscribe
     *
     * @link https://redis.io/commands/punsubscribe
     */
    public function punsubscribe($patterns = null)
    {
    }
Pubsub 查看订阅与发布系统状态,它由数个不同格式的子命令组成
  • pubsub redis命令 PUBSUB <subcommand> [argument [argument ...]]
/**
     * A command allowing you to get information on the Redis pub/sub system
     *
     * @param string       $keyword    String, which can be: "channels", "numsub", or "numpat"
     * @param string|array $argument   Optional, variant.
     *                                 For the "channels" subcommand, you can pass a string pattern.
     *                                 For "numsub" an array of channel names
     *
     * @return array|int Either an integer or an array.
     *   - channels  Returns an array where the members are the matching channels.
     *   - numsub    Returns a key/value array where the keys are channel names and
     *               values are their counts.
     *   - numpat    Integer return containing the number active pattern subscriptions
     *
     * @link    https://redis.io/commands/pubsub
     * @example
     * <pre>
     * $redis->pubsub('channels'); // All channels
     * $redis->pubsub('channels', '*pattern*'); // Just channels matching your pattern
     * $redis->pubsub('numsub', array('chan1', 'chan2')); // Get subscriber counts for 'chan1' and 'chan2'
     * $redis->pubsub('numpat'); // Get the number of pattern subscribers
     * </pre>
     */
    public function pubsub($keyword, $argument)
    {
    }

相关文章

网友评论

      本文标题:Redis 发布订阅

      本文链接:https://www.haomeiwen.com/subject/cpmeuktx.html