the whole shebang

This commit is contained in:
2014-11-25 16:42:40 +01:00
parent 7f74c0613e
commit ab1334c0cf
3686 changed files with 496409 additions and 1 deletions

View File

@@ -0,0 +1,96 @@
<?php namespace Illuminate\Redis;
class Database {
/**
* 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']) and $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'));
return array('default' => new \Predis\Client(array_values($servers)));
}
/**
* 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 \Predis\Client($server);
}
return $clients;
}
/**
* Get a specific Redis connection instance.
*
* @param string $name
* @return \Predis\Connection\SingleConnectionInterface
*/
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);
}
/**
* 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

@@ -0,0 +1,37 @@
<?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['redis'] = $this->app->share(function($app)
{
return new Database($app['config']['database.redis']);
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('redis');
}
}

View File

@@ -0,0 +1,31 @@
{
"name": "illuminate/redis",
"license": "MIT",
"authors": [
{
"name": "Taylor Otwell",
"email": "taylorotwell@gmail.com"
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.0.x",
"predis/predis": "0.*"
},
"require-dev": {
"mockery/mockery": "0.7.2",
"phpunit/phpunit": "3.7.*"
},
"autoload": {
"psr-0": {
"Illuminate\\Redis": ""
}
},
"target-dir": "Illuminate/Redis",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"minimum-stability": "dev"
}