update v 1.0.7.5

This commit is contained in:
Sujit Prasad
2016-06-13 20:41:55 +05:30
parent aa9786d829
commit 283d97e3ea
5078 changed files with 339851 additions and 175995 deletions

View File

@@ -1,138 +1,139 @@
<?php namespace Illuminate\Redis;
<?php
namespace Illuminate\Redis;
use Closure;
use Predis\Client;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Redis\Database as DatabaseContract;
class Database implements DatabaseContract {
class Database implements DatabaseContract
{
/**
* The host address of the database.
*
* @var array
*/
protected $clients;
/**
* The host address of the database.
*
* @var array
*/
protected $clients;
/**
* Create a new Redis connection instance.
*
* @param array $servers
* @return void
*/
public function __construct(array $servers = [])
{
$cluster = Arr::pull($servers, 'cluster');
/**
* Create a new Redis connection instance.
*
* @param array $servers
* @return void
*/
public function __construct(array $servers = array())
{
if (isset($servers['cluster']) && $servers['cluster'])
{
$this->clients = $this->createAggregateClient($servers);
}
else
{
$this->clients = $this->createSingleClients($servers);
}
}
$options = (array) Arr::pull($servers, 'options');
/**
* Create a new aggregate client supporting sharding.
*
* @param array $servers
* @return array
*/
protected function createAggregateClient(array $servers)
{
$servers = array_except($servers, array('cluster'));
if ($cluster) {
$this->clients = $this->createAggregateClient($servers, $options);
} else {
$this->clients = $this->createSingleClients($servers, $options);
}
}
$options = $this->getClientOptions($servers);
/**
* Create a new aggregate client supporting sharding.
*
* @param array $servers
* @param array $options
* @return array
*/
protected function createAggregateClient(array $servers, array $options = [])
{
return ['default' => new Client(array_values($servers), $options)];
}
return array('default' => new Client(array_values($servers), $options));
}
/**
* Create an array of single connection clients.
*
* @param array $servers
* @param array $options
* @return array
*/
protected function createSingleClients(array $servers, array $options = [])
{
$clients = [];
/**
* Create an array of single connection clients.
*
* @param array $servers
* @return array
*/
protected function createSingleClients(array $servers)
{
$clients = array();
foreach ($servers as $key => $server) {
$clients[$key] = new Client($server, $options);
}
$options = $this->getClientOptions($servers);
return $clients;
}
foreach ($servers as $key => $server)
{
$clients[$key] = new Client($server, $options);
}
/**
* Get a specific Redis connection instance.
*
* @param string $name
* @return \Predis\ClientInterface|null
*/
public function connection($name = 'default')
{
return Arr::get($this->clients, $name ?: 'default');
}
return $clients;
}
/**
* Run a command against the Redis database.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function command($method, array $parameters = [])
{
return call_user_func_array([$this->clients['default'], $method], $parameters);
}
/**
* Get any client options from the configuration array.
*
* @param array $servers
* @return array
*/
protected function getClientOptions(array $servers)
{
return isset($servers['options']) ? (array) $servers['options'] : [];
}
/**
* Subscribe to a set of given channels for messages.
*
* @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')
{
$loop = $this->connection($connection)->pubSubLoop();
/**
* Get a specific Redis connection instance.
*
* @param string $name
* @return \Predis\ClientInterface
*/
public function connection($name = 'default')
{
return $this->clients[$name ?: 'default'];
}
call_user_func_array([$loop, $method], (array) $channels);
/**
* Run a command against the Redis database.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function command($method, array $parameters = array())
{
return call_user_func_array(array($this->clients['default'], $method), $parameters);
}
foreach ($loop as $message) {
if ($message->kind === 'message' || $message->kind === 'pmessage') {
call_user_func($callback, $message->payload, $message->channel);
}
}
/**
* Subscribe to a set of given channels for messages.
*
* @param array|string $channels
* @param \Closure $callback
* @param string $connection
* @return void
*/
public function subscribe($channels, Closure $callback, $connection = null)
{
$loop = $this->connection($connection)->pubSubLoop();
unset($loop);
}
call_user_func_array([$loop, 'subscribe'], (array) $channels);
foreach ($loop as $message) {
if ($message->kind === 'message') {
call_user_func($callback, $message->payload, $message->channel);
}
}
unset($loop);
}
/**
* Dynamically make a Redis command.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return $this->command($method, $parameters);
}
/**
* Subscribe to a set of given channels with wildcards.
*
* @param array|string $channels
* @param \Closure $callback
* @param string $connection
* @return void
*/
public function psubscribe($channels, Closure $callback, $connection = null)
{
return $this->subscribe($channels, $callback, $connection, __FUNCTION__);
}
/**
* Dynamically make a Redis command.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return $this->command($method, $parameters);
}
}

View File

@@ -1,37 +1,37 @@
<?php namespace Illuminate\Redis;
<?php
namespace Illuminate\Redis;
use Illuminate\Support\ServiceProvider;
class RedisServiceProvider extends ServiceProvider {
class RedisServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('redis', function($app)
{
return new Database($app['config']['database.redis']);
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('redis');
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('redis', function ($app) {
return new Database($app['config']['database.redis']);
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['redis'];
}
}

View File

@@ -14,9 +14,9 @@
}
],
"require": {
"php": ">=5.4.0",
"illuminate/contracts": "5.0.*",
"illuminate/support": "5.0.*",
"php": ">=5.5.9",
"illuminate/contracts": "5.2.*",
"illuminate/support": "5.2.*",
"predis/predis": "~1.0"
},
"autoload": {
@@ -26,7 +26,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.0-dev"
"dev-master": "5.2-dev"
}
},
"minimum-stability": "dev"