Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

bump up to superbalist/php-pubsub ^2.0 & add publishBatch method #3

Merged
merged 2 commits into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ $adapter->subscribe('my_channel', function ($message) {

// publish messages
$adapter->publish('my_channel', 'HELLO WORLD');
$adapter->publish('my_channel', json_encode(['hello' => 'world']));
$adapter->publish('my_channel', ['hello' => 'world']);
$adapter->publish('my_channel', 1);
$adapter->publish('my_channel', false);

// publish multiple messages
$messages = [
'message 1',
'message 2',
];
$adapter->publishBatch('my_channel', $messages);
```

## Examples
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.0.0 - 2017-05-16

* Bump up to superbalist/php-pubsub ^2.0
* Add new publishBatch method to RedisPubSubAdapter

## 1.0.1 - 2016-09-09

* Allow for older versions of predis/predis - ^0.8|^1.0|^1.1
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"require": {
"php": ">=5.6.0",
"predis/predis": "^0.8|^1.0|^1.1",
"superbalist/php-pubsub": "^1.0"
"superbalist/php-pubsub": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion examples/RedisPublishExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
$adapter = new \Superbalist\PubSub\Redis\RedisPubSubAdapter($client);

$adapter->publish('my_channel', 'HELLO WORLD');
$adapter->publish('my_channel', json_encode(['hello' => 'world']));
$adapter->publish('my_channel', ['hello' => 'world']);
$adapter->publish('my_channel', 1);
$adapter->publish('my_channel', false);
13 changes: 13 additions & 0 deletions src/RedisPubSubAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,17 @@ public function publish($channel, $message)
{
$this->client->publish($channel, Utils::serializeMessage($message));
}

/**
* Publish multiple messages to a channel.
*
* @param string $channel
* @param array $messages
*/
public function publishBatch($channel, array $messages)
{
foreach ($messages as $message) {
$this->publish($channel, $message);
}
}
}
26 changes: 25 additions & 1 deletion tests/RedisPubSubAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,35 @@ public function testPublish()
$client->shouldReceive('publish')
->withArgs([
'channel_name',
'a:1:{s:5:"hello";s:5:"world";}',
'{"hello":"world"}',
])
->once();

$adapter = new RedisPubSubAdapter($client);
$adapter->publish('channel_name', ['hello' => 'world']);
}

public function testPublishBatch()
{
$client = Mockery::mock(Client::class);
$client->shouldReceive('publish')
->withArgs([
'channel_name',
'"message1"',
])
->once();
$client->shouldReceive('publish')
->withArgs([
'channel_name',
'"message2"',
])
->once();

$adapter = new RedisPubSubAdapter($client);
$messages = [
'message1',
'message2',
];
$adapter->publishBatch('channel_name', $messages);
}
}