Skip to content

Commit

Permalink
Working on PHP Redis database. Fixing sub.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 20, 2016
1 parent eb899ea commit 01ed1c8
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/Illuminate/Redis/PhpRedisDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function createClusters(array $clusters, array $options = [])
$options = array_merge($options, (array) Arr::pull($clusters, 'options'));

foreach ($clusters as $name => $servers) {
$this->clients += $this->createAggregateClient($name, $servers, array_merge(
$this->clients[$name] = $this->createAggregateClient($servers, array_merge(
$options, (array) Arr::pull($servers, 'options')
));
}
Expand All @@ -72,29 +72,15 @@ protected function createClusters(array $clusters, array $options = [])
/**
* Create a new aggregate client supporting sharding.
*
* @param string $name
* @param array $servers
* @param array $options
* @return array
*/
protected function createAggregateClient($name, array $servers, array $options = [])
protected function createAggregateClient(array $servers, array $options = [])
{
$servers = array_map([$this, 'buildClusterConnectionString'], $servers);

return [$name => $this->createRedisClusterInstance($servers, $options)];
}

/**
* Build a single cluster seed string from array.
*
* @param array $server
* @return string
*/
protected function buildClusterConnectionString(array $server)
{
return $server['host'].':'.$server['port'].'?'.http_build_query(Arr::only($server, [
'database', 'password', 'prefix', 'read_timeout',
]));
return $this->createRedisClusterInstance(
array_map([$this, 'buildClusterConnectionString'], $servers), $options
);
}

/**
Expand All @@ -103,12 +89,13 @@ protected function buildClusterConnectionString(array $server)
* @param array|string $channels
* @param \Closure $callback
* @param string $connection
* @param string $method
* @return void
*/
public function subscribe($channels, Closure $callback, $connection = null, $method = 'subscribe')
public function subscribe($channels, Closure $callback, $connection = null)
{
call_user_func_array([$this->connection($connection), $method], (array) $channels, $callback);
$this->connection($connection)->subscribe((array) $channels, function ($redis, $channel, $message) use ($callback) {
$callback($message, $channel);
});
}

/**
Expand All @@ -121,7 +108,9 @@ public function subscribe($channels, Closure $callback, $connection = null, $met
*/
public function psubscribe($channels, Closure $callback, $connection = null)
{
$this->subscribe($channels, $callback, $connection, __FUNCTION__);
$this->connection($connection)->psubscribe((array) $channels, function ($redis, $pattern, $channel, $message) use ($callback) {
$callback($message, $channel);
});
}

/**
Expand Down Expand Up @@ -179,4 +168,17 @@ protected function createRedisClusterInstance(array $servers, array $options)
isset($options['persistent']) && $options['persistent']
);
}

/**
* Build a single cluster seed string from array.
*
* @param array $server
* @return string
*/
protected function buildClusterConnectionString(array $server)
{
return $server['host'].':'.$server['port'].'?'.http_build_query(Arr::only($server, [
'database', 'password', 'prefix', 'read_timeout',
]));
}
}

0 comments on commit 01ed1c8

Please sign in to comment.