Update v1.0.6
This commit is contained in:
@@ -1,138 +0,0 @@
|
||||
<?php namespace Illuminate\Redis;
|
||||
|
||||
use Closure;
|
||||
use Predis\Client;
|
||||
use Illuminate\Contracts\Redis\Database as DatabaseContract;
|
||||
|
||||
class Database implements DatabaseContract {
|
||||
|
||||
/**
|
||||
* 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 = array())
|
||||
{
|
||||
if (isset($servers['cluster']) && $servers['cluster'])
|
||||
{
|
||||
$this->clients = $this->createAggregateClient($servers);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->clients = $this->createSingleClients($servers);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new aggregate client supporting sharding.
|
||||
*
|
||||
* @param array $servers
|
||||
* @return array
|
||||
*/
|
||||
protected function createAggregateClient(array $servers)
|
||||
{
|
||||
$servers = array_except($servers, array('cluster'));
|
||||
|
||||
$options = $this->getClientOptions($servers);
|
||||
|
||||
return array('default' => new Client(array_values($servers), $options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an array of single connection clients.
|
||||
*
|
||||
* @param array $servers
|
||||
* @return array
|
||||
*/
|
||||
protected function createSingleClients(array $servers)
|
||||
{
|
||||
$clients = array();
|
||||
|
||||
$options = $this->getClientOptions($servers);
|
||||
|
||||
foreach ($servers as $key => $server)
|
||||
{
|
||||
$clients[$key] = new Client($server, $options);
|
||||
}
|
||||
|
||||
return $clients;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific Redis connection instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Predis\ClientInterface
|
||||
*/
|
||||
public function connection($name = 'default')
|
||||
{
|
||||
return $this->clients[$name ?: 'default'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php namespace Illuminate\Redis;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class RedisServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* 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');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
{
|
||||
"name": "illuminate/redis",
|
||||
"description": "The Illuminate Redis package.",
|
||||
"license": "MIT",
|
||||
"homepage": "http://laravel.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"illuminate/contracts": "5.0.*",
|
||||
"illuminate/support": "5.0.*",
|
||||
"predis/predis": "~1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Redis\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "5.0-dev"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
Reference in New Issue
Block a user