/** *@depends testSubscribeSockerIOChannel */ public function testEmitSocketIOMessage() { $this->sent_data = 'Random string:' . rand(); $redis = new Predis\Client('tcp://redis:6379'); $publish = json_encode(['event' => $this->event_name, 'data' => $this->sent_data]); $result = $redis->publish($this->channel_name, $publish); $this->assertSame(1, $result); }
function publish($data) { $redis = new Predis\Client(); $redis->publish('demo-channel', json_encode($data)); return $data; }
/** * @param string $channel * @param string $message * @return int */ public function publish($channel, $message) { return $this->_redis->publish($channel, $message); }
<?php require __DIR__ . '/../../vendor/autoload.php'; $redis = new Predis\Client('tcp://redis:6379'); $publish = json_encode(['event' => 'MyEvent', 'data' => 'Random string:' . rand()]); $redis->publish('example-channel', $publish); print "Published data: <b>{$publish}</b>";
#!/usr/bin/php <?php require 'vendor/autoload.php'; $client = new Predis\Client(['host' => '127.0.0.1', 'port' => 6379]); $userCount = array('pmcount' => rand(5, 20), 'secount' => rand(5, 10), 'ssecount' => rand(10, 30), 'tlcount' => rand(20, 40)); $channelName = 'redis_data'; $message = 'This is a test message from php redis publisher.'; //Publishing message to redis server $client->publish($channelName, $message); $client->quit(); echo "published test message to channel [{$channelName}] ";
public function notifyUserNewMessage($params) { try { $client = new Predis\Client($this->settings['redis']); $client->publish('chat_room_' . $this->settings['instance_id'] . '_' . $params['chat']->id, $params['chat']->id); } catch (Exception $e) { echo $e->getMessage(); } }