StimmerLove
2018-11-30 05:42 阅读 1.1k

redis subscribe无法使用

这是Pubsub的类

 class Pubsub {
    private $redis;
    public function __construct(){
        $redis = new \Redis();
        $redis->connect('10.127.8.188',6379);
        $this->redis = $redis;
    }

    public function callbak($redis,$channel_name,$msg){
        var_dump(json_encode($redis));
        var_dump($channel_name);
        var_dump($msg);
    }

    public function subChannel($channels){
        function callbak($redis,$channel_name,$msg){
            var_dump(json_encode($redis));
            var_dump($channel_name);
            var_dump($msg);
        }
        $this->redis->subscribe($channels,[$this->redis,'callbak']);
    }

    public function pubMsg($channel,$msg){
        $this->redis->publish($channel,$msg);
    }
}

下面是使用时的代码

 public function pubAction(){
        $redis = new Pubsub();
        $message = '344';
        $channel = 'sub1';
        $redis->pubMsg($channel,$message);
 }
 public function subAction(){
        $redis = new Pubsub();
        $redis->subChannel(array('sub1','sub2','job1','job2'));
 }

问题是发布信息之后,订阅者无法接收到信息,
报错信息:
Redis::subscribe() expects parameter 2 to be a valid callback, class 'Redis' does not have a method 'callbak'
有大神吗,帮忙解决一下

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

相关推荐