3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
22 * Send recent change notifications via Redis Pub/Sub
24 * If the feed URI contains a path component, it will be used to generate a
25 * channel name by stripping the leading slash and replacing any remaining
26 * slashes with '.'. If no path component is present, the channel is set to
27 * 'rc'. If the URI contains a query string, its parameters will be parsed
28 * as RedisConnectionPool options.
31 * $wgRCFeeds['redis'] = array(
32 * 'formatter' => 'JSONRCFeedFormatter',
33 * 'uri' => "redis://127.0.0.1:6379/rc.$wgDBname",
38 class RedisPubSubFeedEngine
extends RCFeedEngine
{
41 * @see FormattedRCFeed::send
43 public function send( array $feed, $line ) {
44 $parsed = wfParseUrl( $feed['uri'] );
45 $server = $parsed['host'];
46 $options = [ 'serializer' => 'none' ];
49 if ( isset( $parsed['port'] ) ) {
50 $server .= ":{$parsed['port']}";
52 if ( isset( $parsed['query'] ) ) {
53 parse_str( $parsed['query'], $options );
55 if ( isset( $parsed['pass'] ) ) {
56 $options['password'] = $parsed['pass'];
58 if ( isset( $parsed['path'] ) ) {
59 $channel = str_replace( '/', '.', ltrim( $parsed['path'], '/' ) );
61 $pool = RedisConnectionPool
::singleton( $options );
62 $conn = $pool->getConnection( $server );
63 if ( $conn !== false ) {
64 $conn->publish( $channel, $line );