Pressroom template verwijderd, website naar root van repo

This commit is contained in:
2020-03-22 15:30:52 +01:00
parent 2cb6a77425
commit f3d1c41e91
7620 changed files with 0 additions and 186900 deletions

View File

@@ -0,0 +1,83 @@
<?php
namespace Illuminate\Redis\Connections;
use Closure;
abstract class Connection
{
/**
* The Predis client.
*
* @var \Predis\Client
*/
protected $client;
/**
* Subscribe to a set of given channels for messages.
*
* @param array|string $channels
* @param \Closure $callback
* @param string $method
* @return void
*/
abstract public function createSubscription($channels, Closure $callback, $method = 'subscribe');
/**
* Get the underlying Redis client.
*
* @return mixed
*/
public function client()
{
return $this->client;
}
/**
* Subscribe to a set of given channels for messages.
*
* @param array|string $channels
* @param \Closure $callback
* @return void
*/
public function subscribe($channels, Closure $callback)
{
return $this->createSubscription($channels, $callback, __FUNCTION__);
}
/**
* Subscribe to a set of given channels with wildcards.
*
* @param array|string $channels
* @param \Closure $callback
* @return void
*/
public function psubscribe($channels, Closure $callback)
{
return $this->createSubscription($channels, $callback, __FUNCTION__);
}
/**
* Run a command against the Redis database.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function command($method, array $parameters = [])
{
return $this->client->{$method}(...$parameters);
}
/**
* Pass other method calls down to the underlying client.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return $this->command($method, $parameters);
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Illuminate\Redis\Connections;
class PhpRedisClusterConnection extends PhpRedisConnection
{
//
}

View File

@@ -0,0 +1,258 @@
<?php
namespace Illuminate\Redis\Connections;
use Closure;
class PhpRedisConnection extends Connection
{
/**
* Create a new Predis connection.
*
* @param \Redis $client
* @return void
*/
public function __construct($client)
{
$this->client = $client;
}
/**
* Returns the value of the given key.
*
* @param string $key
* @return string|null
*/
public function get($key)
{
$result = $this->client->get($key);
return $result !== false ? $result : null;
}
/**
* Get the values of all the given keys.
*
* @param array $keys
* @return array
*/
public function mget(array $keys)
{
return array_map(function ($value) {
return $value !== false ? $value : null;
}, $this->client->mget($keys));
}
/**
* Set the string value in argument as value of the key.
*
* @param string $key
* @param mixed $value
* @param string|null $expireResolution
* @param int|null $expireTTL
* @param string|null $flag
* @return bool
*/
public function set($key, $value, $expireResolution = null, $expireTTL = null, $flag = null)
{
return $this->command('set', [
$key,
$value,
$expireResolution ? [$expireResolution, $flag => $expireTTL] : null,
]);
}
/**
* Removes the first count occurrences of the value element from the list.
*
* @param string $key
* @param int $count
* @param $value $value
* @return int|false
*/
public function lrem($key, $count, $value)
{
return $this->command('lrem', [$key, $value, $count]);
}
/**
* Removes and returns a random element from the set value at key.
*
* @param string $key
* @param int|null $count
* @return mixed|false
*/
public function spop($key, $count = null)
{
return $this->command('spop', [$key]);
}
/**
* Add one or more members to a sorted set or update its score if it already exists.
*
* @param string $key
* @param mixed $dictionary
* @return int
*/
public function zadd($key, ...$dictionary)
{
if (count($dictionary) === 1) {
$_dictionary = [];
foreach ($dictionary[0] as $member => $score) {
$_dictionary[] = $score;
$_dictionary[] = $member;
}
$dictionary = $_dictionary;
}
return $this->client->zadd($key, ...$dictionary);
}
/**
* Execute commands in a pipeline.
*
* @param callable $callback
* @return array|\Redis
*/
public function pipeline(callable $callback = null)
{
$pipeline = $this->client()->pipeline();
return is_null($callback)
? $pipeline
: tap($pipeline, $callback)->exec();
}
/**
* Execute commands in a transaction.
*
* @param callable $callback
* @return array|\Redis
*/
public function transaction(callable $callback = null)
{
$transaction = $this->client()->multi();
return is_null($callback)
? $transaction
: tap($transaction, $callback)->exec();
}
/**
* Evaluate a LUA script serverside, from the SHA1 hash of the script instead of the script itself.
*
* @param string $script
* @param int $numkeys
* @param mixed $arguments
* @return mixed
*/
public function evalsha($script, $numkeys, ...$arguments)
{
return $this->command('evalsha', [
$this->script('load', $script), $arguments, $numkeys,
]);
}
/**
* Proxy a call to the eval function of PhpRedis.
*
* @param array $parameters
* @return mixed
*/
protected function proxyToEval(array $parameters)
{
return $this->command('eval', [
isset($parameters[0]) ? $parameters[0] : null,
array_slice($parameters, 2),
isset($parameters[1]) ? $parameters[1] : null,
]);
}
/**
* Subscribe to a set of given channels for messages.
*
* @param array|string $channels
* @param \Closure $callback
* @return void
*/
public function subscribe($channels, Closure $callback)
{
$this->client->subscribe((array) $channels, function ($redis, $channel, $message) use ($callback) {
$callback($message, $channel);
});
}
/**
* Subscribe to a set of given channels with wildcards.
*
* @param array|string $channels
* @param \Closure $callback
* @return void
*/
public function psubscribe($channels, Closure $callback)
{
$this->client->psubscribe((array) $channels, function ($redis, $pattern, $channel, $message) use ($callback) {
$callback($message, $channel);
});
}
/**
* Subscribe to a set of given channels for messages.
*
* @param array|string $channels
* @param \Closure $callback
* @param string $method
* @return void
*/
public function createSubscription($channels, Closure $callback, $method = 'subscribe')
{
//
}
/**
* Execute a raw command.
*
* @param array $parameters
* @return mixed
*/
public function executeRaw(array $parameters)
{
return $this->command('rawCommand', $parameters);
}
/**
* Disconnects from the Redis instance.
*
* @return void
*/
public function disconnect()
{
$this->client->close();
}
/**
* Pass other method calls down to the underlying client.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
$method = strtolower($method);
if ($method == 'eval') {
return $this->proxyToEval($parameters);
}
if ($method == 'zrangebyscore' || $method == 'zrevrangebyscore') {
$parameters = array_map(function ($parameter) {
return is_array($parameter) ? array_change_key_case($parameter) : $parameter;
}, $parameters);
}
return parent::__call($method, $parameters);
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Illuminate\Redis\Connections;
class PredisClusterConnection extends PredisConnection
{
//
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Illuminate\Redis\Connections;
use Closure;
class PredisConnection extends Connection
{
/**
* Create a new Predis connection.
*
* @param \Predis\Client $client
* @return void
*/
public function __construct($client)
{
$this->client = $client;
}
/**
* Subscribe to a set of given channels for messages.
*
* @param array|string $channels
* @param \Closure $callback
* @param string $method
* @return void
*/
public function createSubscription($channels, Closure $callback, $method = 'subscribe')
{
$loop = $this->pubSubLoop();
call_user_func_array([$loop, $method], (array) $channels);
foreach ($loop as $message) {
if ($message->kind === 'message' || $message->kind === 'pmessage') {
call_user_func($callback, $message->payload, $message->channel);
}
}
unset($loop);
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace Illuminate\Redis\Connectors;
use Redis;
use RedisCluster;
use Illuminate\Support\Arr;
use Illuminate\Redis\Connections\PhpRedisConnection;
use Illuminate\Redis\Connections\PhpRedisClusterConnection;
class PhpRedisConnector
{
/**
* Create a new clustered Predis connection.
*
* @param array $config
* @param array $options
* @return \Illuminate\Redis\PhpRedisConnection
*/
public function connect(array $config, array $options)
{
return new PhpRedisConnection($this->createClient(array_merge(
$config, $options, Arr::pull($config, 'options', [])
)));
}
/**
* Create a new clustered Predis connection.
*
* @param array $config
* @param array $clusterOptions
* @param array $options
* @return \Illuminate\Redis\Connections\PhpRedisClusterConnection
*/
public function connectToCluster(array $config, array $clusterOptions, array $options)
{
$options = array_merge($options, $clusterOptions, Arr::pull($config, 'options', []));
return new PhpRedisClusterConnection($this->createRedisClusterInstance(
array_map([$this, 'buildClusterConnectionString'], $config), $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',
]));
}
/**
* Create the Redis client instance.
*
* @param array $config
* @return \Redis
*/
protected function createClient(array $config)
{
return tap(new Redis, function ($client) use ($config) {
$this->establishConnection($client, $config);
if (! empty($config['password'])) {
$client->auth($config['password']);
}
if (! empty($config['database'])) {
$client->select($config['database']);
}
if (! empty($config['prefix'])) {
$client->setOption(Redis::OPT_PREFIX, $config['prefix']);
}
if (! empty($config['read_timeout'])) {
$client->setOption(Redis::OPT_READ_TIMEOUT, $config['read_timeout']);
}
});
}
/**
* Establish a connection with the Redis host.
*
* @param \Redis $client
* @param array $config
* @return void
*/
protected function establishConnection($client, array $config)
{
$client->{Arr::get($config, 'persistent', false) === true ? 'pconnect' : 'connect'}(
$config['host'], $config['port'], Arr::get($config, 'timeout', 0)
);
}
/**
* Create a new redis cluster instance.
*
* @param array $servers
* @param array $options
* @return \RedisCluster
*/
protected function createRedisClusterInstance(array $servers, array $options)
{
return new RedisCluster(
null,
array_values($servers),
Arr::get($options, 'timeout', 0),
Arr::get($options, 'read_timeout', 0),
isset($options['persistent']) && $options['persistent']
);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Illuminate\Redis\Connectors;
use Predis\Client;
use Illuminate\Support\Arr;
use Illuminate\Redis\Connections\PredisConnection;
use Illuminate\Redis\Connections\PredisClusterConnection;
class PredisConnector
{
/**
* Create a new clustered Predis connection.
*
* @param array $config
* @param array $options
* @return \Illuminate\Redis\Connections\PredisConnection
*/
public function connect(array $config, array $options)
{
$formattedOptions = array_merge(
['timeout' => 10.0], $options, Arr::pull($config, 'options', [])
);
return new PredisConnection(new Client($config, $formattedOptions));
}
/**
* Create a new clustered Predis connection.
*
* @param array $config
* @param array $clusterOptions
* @param array $options
* @return \Illuminate\Redis\Connections\PredisClusterConnection
*/
public function connectToCluster(array $config, array $clusterOptions, array $options)
{
$clusterSpecificOptions = Arr::pull($config, 'options', []);
return new PredisClusterConnection(new Client(array_values($config), array_merge(
$options, $clusterOptions, $clusterSpecificOptions
)));
}
}

View File

@@ -0,0 +1,129 @@
<?php
namespace Illuminate\Redis;
use Illuminate\Support\Arr;
use InvalidArgumentException;
use Illuminate\Contracts\Redis\Factory;
class RedisManager implements Factory
{
/**
* The name of the default driver.
*
* @var string
*/
protected $driver;
/**
* The Redis server configurations.
*
* @var array
*/
protected $config;
/**
* The Redis connections.
*
* @var mixed
*/
protected $connections;
/**
* Create a new Redis manager instance.
*
* @param string $driver
* @param array $config
*/
public function __construct($driver, array $config)
{
$this->driver = $driver;
$this->config = $config;
}
/**
* Get a Redis connection by name.
*
* @param string|null $name
* @return \Illuminate\Redis\Connections\Connection
*/
public function connection($name = null)
{
$name = $name ?: 'default';
if (isset($this->connections[$name])) {
return $this->connections[$name];
}
return $this->connections[$name] = $this->resolve($name);
}
/**
* Resolve the given connection by name.
*
* @param string|null $name
* @return \Illuminate\Redis\Connections\Connection
*
* @throws \InvalidArgumentException
*/
public function resolve($name = null)
{
$name = $name ?: 'default';
$options = Arr::get($this->config, 'options', []);
if (isset($this->config[$name])) {
return $this->connector()->connect($this->config[$name], $options);
}
if (isset($this->config['clusters'][$name])) {
return $this->resolveCluster($name);
}
throw new InvalidArgumentException(
"Redis connection [{$name}] not configured."
);
}
/**
* Resolve the given cluster connection by name.
*
* @param string $name
* @return \Illuminate\Redis\Connections\Connection
*/
protected function resolveCluster($name)
{
$clusterOptions = Arr::get($this->config, 'clusters.options', []);
return $this->connector()->connectToCluster(
$this->config['clusters'][$name], $clusterOptions, Arr::get($this->config, 'options', [])
);
}
/**
* Get the connector instance for the current driver.
*
* @return \Illuminate\Redis\Connectors\PhpRedisConnector|\Illuminate\Redis\Connectors\PredisConnector
*/
protected function connector()
{
switch ($this->driver) {
case 'predis':
return new Connectors\PredisConnector;
case 'phpredis':
return new Connectors\PhpRedisConnector;
}
}
/**
* Pass methods onto the default Redis connection.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return $this->connection()->{$method}(...$parameters);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Illuminate\Redis;
use Illuminate\Support\Arr;
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) {
$config = $app->make('config')->get('database.redis');
return new RedisManager(Arr::pull($config, 'client', 'predis'), $config);
});
$this->app->bind('redis.connection', function ($app) {
return $app['redis']->connection();
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['redis', 'redis.connection'];
}
}

View File

@@ -0,0 +1,36 @@
{
"name": "illuminate/redis",
"description": "The Illuminate Redis package.",
"license": "MIT",
"homepage": "https://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"require": {
"php": ">=5.6.4",
"illuminate/contracts": "5.4.*",
"illuminate/support": "5.4.*",
"predis/predis": "~1.0"
},
"autoload": {
"psr-4": {
"Illuminate\\Redis\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "5.4-dev"
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
}