Merge "Test BagOStuff->incr method"
[lhc/web/wiklou.git] / includes / rcfeed / RedisPubSubFeedEngine.php
1 <?php
2 class RedisPubSubFeedEngine implements RCFeedEngine {
3 /**
4 * Emit a recent change notification via Redis Pub/Sub
5 *
6 * If the feed URI contains a path component, it will be used to generate a
7 * channel name by stripping the leading slash and replacing any remaining
8 * slashes with '.'. If no path component is present, the channel is set to
9 * 'rc'. If the URI contains a query string, its parameters will be parsed
10 * as RedisConnectionPool options.
11 *
12 * @example $wgRCFeeds['redis'] = array(
13 * 'formatter' => 'JSONRCFeedFormatter',
14 * 'uri' => "redis://127.0.0.1:6379/rc.$wgDBname",
15 * );
16 *
17 * @since 1.22
18 */
19 public function send( array $feed, $line ) {
20 $parsed = parse_url( $feed['uri'] );
21 $server = $parsed['host'];
22 $options = array( 'serializer' => 'none' );
23 $channel = 'rc';
24
25 if ( isset( $parsed['port'] ) ) {
26 $server .= ":{$parsed['port']}";
27 }
28 if ( isset( $parsed['query'] ) ) {
29 parse_str( $parsed['query'], $options );
30 }
31 if ( isset( $parsed['pass'] ) ) {
32 $options['password'] = $parsed['pass'];
33 }
34 if ( isset( $parsed['path'] ) ) {
35 $channel = str_replace( '/', '.', ltrim( $parsed['path'], '/' ) );
36 }
37 $pool = RedisConnectionPool::singleton( $options );
38 $conn = $pool->getConnection( $server );
39 $conn->publish( $channel, $line );
40 }
41 }