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

Commit dd6b24c

Browse files
Merge pull request #3 from Superbalist/bump-up-to-php-pubsub-2
bump up to superbalist/php-pubsub ^2.0 & add publishBatch method
2 parents 19dd6cf + 5da5968 commit dd6b24c

File tree

6 files changed

+53
-4
lines changed

6 files changed

+53
-4
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@ $adapter->subscribe('my_channel', function ($message) {
3737

3838
// publish messages
3939
$adapter->publish('my_channel', 'HELLO WORLD');
40-
$adapter->publish('my_channel', json_encode(['hello' => 'world']));
40+
$adapter->publish('my_channel', ['hello' => 'world']);
4141
$adapter->publish('my_channel', 1);
4242
$adapter->publish('my_channel', false);
43+
44+
// publish multiple messages
45+
$messages = [
46+
'message 1',
47+
'message 2',
48+
];
49+
$adapter->publishBatch('my_channel', $messages);
4350
```
4451

4552
## Examples

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 2.0.0 - 2017-05-16
4+
5+
* Bump up to superbalist/php-pubsub ^2.0
6+
* Add new publishBatch method to RedisPubSubAdapter
7+
38
## 1.0.1 - 2016-09-09
49

510
* Allow for older versions of predis/predis - ^0.8|^1.0|^1.1

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"require": {
1212
"php": ">=5.6.0",
1313
"predis/predis": "^0.8|^1.0|^1.1",
14-
"superbalist/php-pubsub": "^1.0"
14+
"superbalist/php-pubsub": "^2.0"
1515
},
1616
"autoload": {
1717
"psr-4": {

examples/RedisPublishExample.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
$adapter = new \Superbalist\PubSub\Redis\RedisPubSubAdapter($client);
1414

1515
$adapter->publish('my_channel', 'HELLO WORLD');
16-
$adapter->publish('my_channel', json_encode(['hello' => 'world']));
16+
$adapter->publish('my_channel', ['hello' => 'world']);
1717
$adapter->publish('my_channel', 1);
1818
$adapter->publish('my_channel', false);

src/RedisPubSubAdapter.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,17 @@ public function publish($channel, $message)
6363
{
6464
$this->client->publish($channel, Utils::serializeMessage($message));
6565
}
66+
67+
/**
68+
* Publish multiple messages to a channel.
69+
*
70+
* @param string $channel
71+
* @param array $messages
72+
*/
73+
public function publishBatch($channel, array $messages)
74+
{
75+
foreach ($messages as $message) {
76+
$this->publish($channel, $message);
77+
}
78+
}
6679
}

tests/RedisPubSubAdapterTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,35 @@ public function testPublish()
4343
$client->shouldReceive('publish')
4444
->withArgs([
4545
'channel_name',
46-
'a:1:{s:5:"hello";s:5:"world";}',
46+
'{"hello":"world"}',
4747
])
4848
->once();
4949

5050
$adapter = new RedisPubSubAdapter($client);
5151
$adapter->publish('channel_name', ['hello' => 'world']);
5252
}
53+
54+
public function testPublishBatch()
55+
{
56+
$client = Mockery::mock(Client::class);
57+
$client->shouldReceive('publish')
58+
->withArgs([
59+
'channel_name',
60+
'"message1"',
61+
])
62+
->once();
63+
$client->shouldReceive('publish')
64+
->withArgs([
65+
'channel_name',
66+
'"message2"',
67+
])
68+
->once();
69+
70+
$adapter = new RedisPubSubAdapter($client);
71+
$messages = [
72+
'message1',
73+
'message2',
74+
];
75+
$adapter->publishBatch('channel_name', $messages);
76+
}
5377
}

0 commit comments

Comments
 (0)