Reputation: 451
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?
Upvotes: 1
Views: 2446
Reputation: 451
I go it working. The redis server on azure by default enforces SSL connections on port 6380. I disabled this so it allows non-SSL connections on port 6379. Now the connection is:
$redis = Redis::publish('test-channel', json_encode(['foo' => 'bar']));
Upvotes: 1
Reputation: 40909
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.
Upvotes: 0