[李景山php]每天laravel-20160921|Redis Database.php
来源:互联网 发布:java软件开发简历范文 编辑:程序博客网 时间:2024/05/22 12:55
<?phpnamespace Illuminate\Redis;use Closure;use Predis\Client;use Illuminate\Support\Arr;use Illuminate\Contracts\Redis\Database as DatabaseContract;// this is Redis namespace , father is Database Contractclass Database implements DatabaseContract{// class Database implements Database Contract /** * The host address of the database. * * @var array */ protected $clients;// The host address of the database. // host not hot , ok // host address is like 127.0.0.1 /** * Create a new Redis connection instance. * * @param array $servers * @return void */ public function __construct(array $servers = []) { $cluster = Arr::pull($servers, 'cluster');// cluster is lots of servers $options = (array) Arr::pull($servers, 'options');// pull servers // get options if ($cluster) {// if it is a cluster ,use first way to make it $this->clients = $this->createAggregateClient($servers, $options); } else {// other way $this->clients = $this->createSingleClients($servers, $options); } }// Create a new Redis connection instance /** * 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)]; // set the with server and options }//Create a new aggregate client supporting sharding /** * Create an array of single connection clients. * * @param array $servers * @param array $options * @return array */ protected function createSingleClients(array $servers, array $options = []) { $clients = [];// create Single Clients make clients foreach ($servers as $key => $server) {// a Single Client $clients[$key] = new Client($server, $options); } return $clients; }// make a single Clients /** * 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'); }//Get a specific Redis connection instance. // Get a instance about you self want /** * 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); }// Run a command against the Redis database // use this method call_user_func_array /** * 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();// loop call_user_func_array([$loop, $method], (array) $channels);// call user func array foreach ($loop as $message) { if ($message->kind === 'message' || $message->kind === 'pmessage') { call_user_func($callback, $message->payload, $message->channel);// call_user_func } }// loop like message unset($loop); }//Subscribe /** * 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__); }// Subscribe to a set of given channels with wildcards /** * Dynamically make a Redis command. * * @param string $method * @param array $parameters * @return mixed */ public function __call($method, $parameters) { return $this->command($method, $parameters); }// very good method, }
0 0
- [李景山php]每天laravel-20160921|Redis Database.php
- [李景山php]每天laravel-20160922|RedisServicProvider.php
- [李景山php]每天laravel-20160923|Hub.php
- [李景山php]每天laravel-20160924|PiplineServiceProvider.php
- [李景山php]每天laravel-20160925|Pipeline.php
- [李景山php]每天laravel-20160926|DatabasePresenceVerifier.php
- [李景山php]每天laravel-20160927|Factory.php
- [李景山php]每天laravel-20160928|PresenceVerifierInterface.php
- [李景山php]每天laravel-20160929|ValidatesWhenResolved.php
- [李景山php]每天laravel-20160930|ValidationException.php
- [李景山php]每天laravel-20161001|ValidationServiceProvider.php
- [李景山php]每天laravel-20161016|JsonResponse.php
- [李景山php]每天laravel-20161017|ResponseTrait.php
- [李景山php]每天laravel-20161017|UploadedFile.php
- [李景山php]每天laravel-20161023|Reponse.php
- [李景山php]每天laravel-20161024|ArrayLoader.php
- [李景山php]每天laravel-20161025|LoaderInterface.php
- [李景山php]每天laravel-20161026|TranslationServiceProvider.php
- MPI和MapReduce对比
- 【codeforces】Uncowed Forces
- MongoDB从不懂到装懂其四(数据备份、恢复、导入、导出)
- <<More Effective C++>>读书笔记2: 运算符
- day2 HDU 2141 Can you find it?
- [李景山php]每天laravel-20160921|Redis Database.php
- 基于FPGA的Alpha半透明图像叠加算法实现
- 为什么析构函数常声明为虚函数?
- python 模拟登录csdn并获取博客列表等操作
- 快学scala 第十一章 操作符 读书笔记及习题答案代码
- 深入理解 Android 中的 Matrix
- Android 6.0 通话UI设计模式分析(MVC\MVP\MVVM)
- Post Views Options怎么设置,WP-PostViews的后台设置五步法详解
- java反向工程神器ermaster