[李景山php]每天laravel-20160921|Redis Database.php
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了[李景山php]每天laravel-20160921|Redis Database.php,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4668字,纯文字阅读大概需要7分钟。
内容图文
![[李景山php]每天laravel-20160921|Redis Database.php](/upload/InfoBanner/zyjiaocheng/468/b1f11b3a78bc4748b4f3756f6cc73e29.jpg)
<?php namespace 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 Contract class 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, }
本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1828664
[李景山php]每天laravel-20160921|Redis Database.php
标签:php
本文系统来源:http://jingshanls.blog.51cto.com/3357095/1828664
内容总结
以上是互联网集市为您收集整理的[李景山php]每天laravel-20160921|Redis Database.php全部内容,希望文章能够帮你解决[李景山php]每天laravel-20160921|Redis Database.php所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。