douzhen1234 2016-08-19 11:47
浏览 156

尝试在laravel上发布到redis时,在null上调用成员函数publish()

I am trying to publish stuff to redis but I get this error:

Call to a member function publish() on null.

Not sure whats going on. This is my code. Works well on the local environment but on the server the above error message shows. I have the following code in a controller. The website is hosted on windows azure appservice. I have also installed the predis/predis dependency.

$redis = Redis::connection(6380)->publish('test-channel', json_encode(['foo' => 'bar']));

Am I not connecting to redis or something?

  • 写回答

2条回答 默认 最新

  • dtj4307 2016-08-19 13:24
    关注

    You should pass the connection name to the connection() method

    $redis = Redis::connection('my_connection')->publish('test-channel', json_encode(['foo' => 'bar']));
    

    or just skip it, if you intend to use the default connection.

    $redis = Redis::publish('test-channel', json_encode(['foo' => 'bar']));
    

    Redis connections should be defined in your config/database.php file.

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥50 成都蓉城足球俱乐部小程序抢票