作者 曹东东
正在显示 39 个修改的文件 包含 4619 行增加 和 68 行删除

要显示太多修改。

为保证性能只显示 39 of 39+ 个文件。

  1 +<?php
  2 +namespace app\common\helper;
  3 +use think\Queue;
  4 +
  5 +
  6 +/***
  7 + * 队列生产者助手类
  8 + */
  9 +class QueueHelper{
  10 +
  11 + private $jobHandlerClassName = 'app\index\controller\job\Project'; //消费者类(处理业务逻辑类)
  12 + private $jobQueueName = 'checkItem'; //队列名称
  13 +
  14 + public function __construct($jobQueueName = null, $jobHandlerClassName = null)
  15 + {
  16 +
  17 + $this->jobHandlerClassName = $jobHandlerClassName ? $jobHandlerClassName : $this->jobHandlerClassName;
  18 + $this->jobQueueName = $jobQueueName ? $jobQueueName : $this->jobQueueName;
  19 + }
  20 +
  21 + /**
  22 + * @param array $jobData 消费者需要的参数
  23 + * @param $delayTime //延迟时间 秒
  24 + * @return bool
  25 + */
  26 + public function delay(array $jobData = array(),$delayTime = null)
  27 + {
  28 + $isPushed = Queue::later($delayTime,$this->jobHandlerClassName,$jobData,$this->jobQueueName); //把任务分配到队列中,延迟10s后执行
  29 + // database 驱动时,返回值为 1|false ; redis 驱动时,返回值为 随机字符串|false
  30 + if( $isPushed !== false ){
  31 + return true;
  32 + }else{
  33 + return false;
  34 + }
  35 + }
  36 +
  37 + /**
  38 + * @param array $jobData 消费者需要的参数
  39 + * @return bool
  40 + */
  41 + public function present(array $jobData = array())
  42 + {
  43 + $isPushed = Queue::push( $this->jobHandlerClassName , $jobData , $this->jobQueueName );
  44 + // database 驱动时,返回值为 1|false ; redis 驱动时,返回值为 随机字符串|false
  45 + if( $isPushed !== false ){
  46 + return true;
  47 + }else{
  48 + return false;
  49 + }
  50 + }
  51 +
  52 +
  53 +
  54 +
  55 +
  56 +
  57 +
  58 +
  59 +
  60 +
  61 +
  62 +
  63 +
  64 +
  65 +
  66 +
  67 +
  68 +
  69 +
  70 +
  71 +
  72 +
  73 +
  74 +
  75 +
  76 +
  77 +
  78 +
  79 +}
  80 +
1 -<?php  
2 -  
3 -namespace app\index\controller\job;  
4 -use think\Queue;  
5 -  
6 -class Jobtest  
7 -{  
8 - //生产者测试  
9 - public function test()  
10 - {  
11 - // 1.当前任务将由哪个类来负责处理。  
12 - // 当轮到该任务时,系统将生成一个该类的实例,并调用其 fire 方法  
13 - $jobHandlerClassName = 'app\index\controller\job\Project';  
14 -  
15 - // 2.当前任务归属的队列名称,如果为新队列,会自动创建  
16 - $jobQueueName = "checkItem";  
17 -  
18 - // 3.当前任务所需的业务数据 . 不能为 resource 类型,其他类型最终将转化为json形式的字符串  
19 - $jobData = ['name' => 'test_01'] ;  
20 - // 4.将该任务推送到消息队列,等待对应的消费者去执行  
21 -// $isPushed = Queue::push( $jobHandlerClassName , $jobData , $jobQueueName );  
22 - $isPushed = Queue::later(30,$jobHandlerClassName,$jobData,$jobQueueName); //把任务分配到队列中,延迟10s后执行  
23 -  
24 - // database 驱动时,返回值为 1|false ; redis 驱动时,返回值为 随机字符串|false  
25 - if( $isPushed !== false ){  
26 - echo date('Y-m-d H:i:s') . " a new Hello Job is Pushed to the MQ"."<br>";  
27 - }else{  
28 - echo 'something went wrong.';  
29 - }  
30 - }  
31 -  
32 -}  
33 -  
34 -  
35 -  
36 -  
37 -  
38 -  
39 -  
40 -  
41 -  
42 -  
43 -  
44 -  
45 -  
46 -  
47 -  
48 -  
49 -  
50 -  
51 -  
52 -  
53 -  
54 -  
1 <?php 1 <?php
2 2
3 namespace app\index\controller\job; 3 namespace app\index\controller\job;
  4 +use app\school\model\project_common\ProjectRegister;
  5 +use app\school\model\setting\ProjectFormSet;
  6 +use Predis\Client;
4 use think\queue\Job; 7 use think\queue\Job;
5 use think\Db; 8 use think\Db;
6 9
7 class Project 10 class Project
8 { 11 {
  12 + public function test()
  13 + {
  14 + $isJobDone = $this->doHelloJob(['container_id' => 99,'project_type_id' => 248,'user_id' => 13844,'register_id' => '489','project_details' => 490]);
  15 + }
9 //消费者 16 //消费者
10 public function fire(Job $job,$data) { 17 public function fire(Job $job,$data) {
11 // 有些消息在到达消费者时,可能已经不再需要执行了 18 // 有些消息在到达消费者时,可能已经不再需要执行了
@@ -20,14 +27,10 @@ class Project @@ -20,14 +27,10 @@ class Project
20 if ($isJobDone) { 27 if ($isJobDone) {
21 // 如果任务执行成功, 记得删除任务 28 // 如果任务执行成功, 记得删除任务
22 $job->delete(); 29 $job->delete();
23 - print("<info>Hello Job has been done and deleted"."</info>\n");  
24 }else{ 30 }else{
25 - if ($job->attempts() > 3) { 31 + if ($job->attempts() > 2) {
26 //通过这个方法可以检查这个任务已经重试了几次了 32 //通过这个方法可以检查这个任务已经重试了几次了
27 - print("<warn>Hello Job has been retried more than 3 times!"."</warn>\n");  
28 $job->delete(); 33 $job->delete();
29 - // 也可以重新发布这个任务  
30 - //print("<info>Hello Job will be availabe again after 2s."."</info>\n");  
31 //$job->release(2); //$delay为延迟时间,表示该任务延迟2秒后再执行 34 //$job->release(2); //$delay为延迟时间,表示该任务延迟2秒后再执行
32 } 35 }
33 } 36 }
@@ -43,13 +46,83 @@ class Project @@ -43,13 +46,83 @@ class Project
43 } 46 }
44 47
45 /** 48 /**
46 - * 根据消息中的数据进行实际的业务处理... 49 + * 大创报名查重
47 */ 50 */
48 - private function doHelloJob($data) 51 +// private function doHelloJob($data)
  52 + public function doHelloJob($data)
49 { 53 {
50 -// print("<info>item Job has been exec"."</info>\n");  
51 -// return true;  
52 - $result = Db::name('job_test')->insert(['name' => $data['name'],'data' => json_encode($data,true),'create_time' => time()]); 54 + $server = array(
  55 + 'host' => 'r-8vb3mizdy07emeuv4upd.redis.zhangbei.rds.aliyuncs.com',//IP
  56 + 'port' => 6379, //端口
  57 + 'password' => 'Yundai2019', //密码
  58 + );
  59 + $redisKey = 'checkProject:'.$data['container_id'].'_'.$data['project_type_id'];
  60 + $redis = new Client($server);//实例化
  61 + $redis->select(8);
  62 + $infos = $redis->hgetall($redisKey);
  63 +
  64 + //该组别下文本报名数据
  65 + if(empty($infos)) {
  66 + return true;
  67 + }
  68 + //自己的报名数据
  69 + if(array_key_exists($data['user_id'].'_'.$data['register_id'],$infos)) {
  70 + $checkData = json_decode($infos[$data['user_id'].'_'.$data['register_id']],true);
  71 + }else {
  72 + //Redis中不存在 查询数据库
  73 + $selfDetail = Db::name('project_register_details')->where(['id' => $data['project_details']])->find();
  74 + $selfFields = json_decode($selfDetail['project_details'],true);
  75 + $checkData = array_merge($selfFields['reg'],$selfFields['details']);
  76 + }
  77 +
  78 + //查询该组别下 表单项
  79 + $map['project_type_id'] = $data['project_type_id'];
  80 + $map['stage_type'] = ['in',['reg','details']];
  81 + $formSets = ProjectFormSet::all($map);
  82 +
  83 + $textField = [];
  84 + foreach ($formSets as $value) {
  85 + $fields_setting = json_decode($value['fields_setting'],true);
  86 + foreach ($fields_setting as $v) {
  87 + if($v['type'] == 'input' || $v['type'] == 'textarea') {
  88 + if(array_key_exists($v['name'],$checkData)) {
  89 + $textField[$v['name']] = $checkData[$v['name']];
  90 + }else {
  91 + $textField[$v['name']] = '';
  92 + }
  93 + }
  94 + }
  95 + }
  96 + unset($infos[$data['user_id'].'_'.$data['register_id']]);
  97 + if(empty($textField)) {
  98 + return true;
  99 + }
  100 + $rate = 100 / count($textField);
  101 + $rateSort = [];
  102 +
  103 + dump($infos);die;
  104 + $result = [];
  105 + foreach ($infos as $v) {
  106 + $repetitionRate = 0;
  107 + $tmp = json_decode($v,true);
  108 + foreach ($textField as $key => $value) {
  109 + //如果存在 校验重复度
  110 + if(array_key_exists($key,$tmp)) {
  111 + dump($key);
  112 + dump($tmp[$key]);
  113 + dump($value);
  114 + $value = '项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222项目名称222222';
  115 + $tmp[$key] = '项目名称222222asdasdasdasd阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大阿斯达四大';
  116 + similar_text($value,$tmp[$key],$percent);
  117 + dump($percent);die;
  118 + }
  119 + }
  120 +
  121 + dump($tmp);die;
  122 +
  123 + }
  124 +
  125 + $result = Db::name('job_test')->insert(['name' => 1,'data' => 1,'create_time' => time()]);
53 if($result) { 126 if($result) {
54 return true; 127 return true;
55 }else { 128 }else {
@@ -30,7 +30,8 @@ @@ -30,7 +30,8 @@
30 "ext-pdo": "*", 30 "ext-pdo": "*",
31 "endroid/qrcode": "^2.1", 31 "endroid/qrcode": "^2.1",
32 "alibabacloud/sdk": "^1.8", 32 "alibabacloud/sdk": "^1.8",
33 - "topthink/think-queue": "1.1.4" 33 + "topthink/think-queue": "1.1.4",
  34 + "predis/predis": "^1.1"
34 }, 35 },
35 "config": { 36 "config": {
36 "preferred-install": "dist", 37 "preferred-install": "dist",
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 4 "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 "This file is @generated automatically" 5 "This file is @generated automatically"
6 ], 6 ],
7 - "content-hash": "6ff2165648c741dd2106ef45f054aece", 7 + "content-hash": "7313045feb4b2ac91012b4ae2e6806f6",
8 "packages": [ 8 "packages": [
9 { 9 {
10 "name": "adbario/php-dot-notation", 10 "name": "adbario/php-dot-notation",
@@ -2196,6 +2196,78 @@ @@ -2196,6 +2196,78 @@
2196 "time": "2021-10-28T11:13:42+00:00" 2196 "time": "2021-10-28T11:13:42+00:00"
2197 }, 2197 },
2198 { 2198 {
  2199 + "name": "predis/predis",
  2200 + "version": "v1.1.10",
  2201 + "source": {
  2202 + "type": "git",
  2203 + "url": "https://github.com/predis/predis.git",
  2204 + "reference": "a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e"
  2205 + },
  2206 + "dist": {
  2207 + "type": "zip",
  2208 + "url": "https://api.github.com/repos/predis/predis/zipball/a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e",
  2209 + "reference": "a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e",
  2210 + "shasum": "",
  2211 + "mirrors": [
  2212 + {
  2213 + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
  2214 + "preferred": true
  2215 + }
  2216 + ]
  2217 + },
  2218 + "require": {
  2219 + "php": ">=5.3.9"
  2220 + },
  2221 + "require-dev": {
  2222 + "phpunit/phpunit": "~4.8"
  2223 + },
  2224 + "suggest": {
  2225 + "ext-curl": "Allows access to Webdis when paired with phpiredis",
  2226 + "ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol"
  2227 + },
  2228 + "type": "library",
  2229 + "autoload": {
  2230 + "psr-4": {
  2231 + "Predis\\": "src/"
  2232 + }
  2233 + },
  2234 + "notification-url": "https://packagist.org/downloads/",
  2235 + "license": [
  2236 + "MIT"
  2237 + ],
  2238 + "authors": [
  2239 + {
  2240 + "name": "Daniele Alessandri",
  2241 + "email": "suppakilla@gmail.com",
  2242 + "homepage": "http://clorophilla.net",
  2243 + "role": "Creator & Maintainer"
  2244 + },
  2245 + {
  2246 + "name": "Till Krüss",
  2247 + "homepage": "https://till.im",
  2248 + "role": "Maintainer"
  2249 + }
  2250 + ],
  2251 + "description": "Flexible and feature-complete Redis client for PHP and HHVM",
  2252 + "homepage": "http://github.com/predis/predis",
  2253 + "keywords": [
  2254 + "nosql",
  2255 + "predis",
  2256 + "redis"
  2257 + ],
  2258 + "support": {
  2259 + "issues": "https://github.com/predis/predis/issues",
  2260 + "source": "https://github.com/predis/predis/tree/v1.1.10"
  2261 + },
  2262 + "funding": [
  2263 + {
  2264 + "url": "https://github.com/sponsors/tillkruss",
  2265 + "type": "github"
  2266 + }
  2267 + ],
  2268 + "time": "2022-01-05T17:46:08+00:00"
  2269 + },
  2270 + {
2199 "name": "psr/cache", 2271 "name": "psr/cache",
2200 "version": "1.0.1", 2272 "version": "1.0.1",
2201 "source": { 2273 "source": {
@@ -38,6 +38,7 @@ return array( @@ -38,6 +38,7 @@ return array(
38 'Psr\\Http\\Client\\' => array($vendorDir . '/psr/http-client/src'), 38 'Psr\\Http\\Client\\' => array($vendorDir . '/psr/http-client/src'),
39 'Psr\\Container\\' => array($vendorDir . '/psr/container/src'), 39 'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
40 'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'), 40 'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
  41 + 'Predis\\' => array($vendorDir . '/predis/predis/src'),
41 'PhpZip\\' => array($vendorDir . '/nelexa/zip/src'), 42 'PhpZip\\' => array($vendorDir . '/nelexa/zip/src'),
42 'PhpOffice\\PhpSpreadsheet\\' => array($vendorDir . '/phpoffice/phpspreadsheet/src/PhpSpreadsheet'), 43 'PhpOffice\\PhpSpreadsheet\\' => array($vendorDir . '/phpoffice/phpspreadsheet/src/PhpSpreadsheet'),
43 'PHPMailer\\PHPMailer\\' => array($vendorDir . '/phpmailer/phpmailer/src'), 44 'PHPMailer\\PHPMailer\\' => array($vendorDir . '/phpmailer/phpmailer/src'),
@@ -80,6 +80,7 @@ class ComposerStaticInitbbe846bc22704b0a31b1a4a1369e02e4 @@ -80,6 +80,7 @@ class ComposerStaticInitbbe846bc22704b0a31b1a4a1369e02e4
80 'Psr\\Http\\Client\\' => 16, 80 'Psr\\Http\\Client\\' => 16,
81 'Psr\\Container\\' => 14, 81 'Psr\\Container\\' => 14,
82 'Psr\\Cache\\' => 10, 82 'Psr\\Cache\\' => 10,
  83 + 'Predis\\' => 7,
83 'PhpZip\\' => 7, 84 'PhpZip\\' => 7,
84 'PhpOffice\\PhpSpreadsheet\\' => 25, 85 'PhpOffice\\PhpSpreadsheet\\' => 25,
85 'PHPMailer\\PHPMailer\\' => 20, 86 'PHPMailer\\PHPMailer\\' => 20,
@@ -256,6 +257,10 @@ class ComposerStaticInitbbe846bc22704b0a31b1a4a1369e02e4 @@ -256,6 +257,10 @@ class ComposerStaticInitbbe846bc22704b0a31b1a4a1369e02e4
256 array ( 257 array (
257 0 => __DIR__ . '/..' . '/psr/cache/src', 258 0 => __DIR__ . '/..' . '/psr/cache/src',
258 ), 259 ),
  260 + 'Predis\\' =>
  261 + array (
  262 + 0 => __DIR__ . '/..' . '/predis/predis/src',
  263 + ),
259 'PhpZip\\' => 264 'PhpZip\\' =>
260 array ( 265 array (
261 0 => __DIR__ . '/..' . '/nelexa/zip/src', 266 0 => __DIR__ . '/..' . '/nelexa/zip/src',
@@ -2182,6 +2182,81 @@ @@ -2182,6 +2182,81 @@
2182 "install-path": "../pimple/pimple" 2182 "install-path": "../pimple/pimple"
2183 }, 2183 },
2184 { 2184 {
  2185 + "name": "predis/predis",
  2186 + "version": "v1.1.10",
  2187 + "version_normalized": "1.1.10.0",
  2188 + "source": {
  2189 + "type": "git",
  2190 + "url": "https://github.com/predis/predis.git",
  2191 + "reference": "a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e"
  2192 + },
  2193 + "dist": {
  2194 + "type": "zip",
  2195 + "url": "https://api.github.com/repos/predis/predis/zipball/a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e",
  2196 + "reference": "a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e",
  2197 + "shasum": "",
  2198 + "mirrors": [
  2199 + {
  2200 + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
  2201 + "preferred": true
  2202 + }
  2203 + ]
  2204 + },
  2205 + "require": {
  2206 + "php": ">=5.3.9"
  2207 + },
  2208 + "require-dev": {
  2209 + "phpunit/phpunit": "~4.8"
  2210 + },
  2211 + "suggest": {
  2212 + "ext-curl": "Allows access to Webdis when paired with phpiredis",
  2213 + "ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol"
  2214 + },
  2215 + "time": "2022-01-05T17:46:08+00:00",
  2216 + "type": "library",
  2217 + "installation-source": "dist",
  2218 + "autoload": {
  2219 + "psr-4": {
  2220 + "Predis\\": "src/"
  2221 + }
  2222 + },
  2223 + "notification-url": "https://packagist.org/downloads/",
  2224 + "license": [
  2225 + "MIT"
  2226 + ],
  2227 + "authors": [
  2228 + {
  2229 + "name": "Daniele Alessandri",
  2230 + "email": "suppakilla@gmail.com",
  2231 + "homepage": "http://clorophilla.net",
  2232 + "role": "Creator & Maintainer"
  2233 + },
  2234 + {
  2235 + "name": "Till Krüss",
  2236 + "homepage": "https://till.im",
  2237 + "role": "Maintainer"
  2238 + }
  2239 + ],
  2240 + "description": "Flexible and feature-complete Redis client for PHP and HHVM",
  2241 + "homepage": "http://github.com/predis/predis",
  2242 + "keywords": [
  2243 + "nosql",
  2244 + "predis",
  2245 + "redis"
  2246 + ],
  2247 + "support": {
  2248 + "issues": "https://github.com/predis/predis/issues",
  2249 + "source": "https://github.com/predis/predis/tree/v1.1.10"
  2250 + },
  2251 + "funding": [
  2252 + {
  2253 + "url": "https://github.com/sponsors/tillkruss",
  2254 + "type": "github"
  2255 + }
  2256 + ],
  2257 + "install-path": "../predis/predis"
  2258 + },
  2259 + {
2185 "name": "psr/cache", 2260 "name": "psr/cache",
2186 "version": "1.0.1", 2261 "version": "1.0.1",
2187 "version_normalized": "1.0.1.0", 2262 "version_normalized": "1.0.1.0",
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 'type' => 'project', 5 'type' => 'project',
6 'install_path' => __DIR__ . '/../../', 6 'install_path' => __DIR__ . '/../../',
7 'aliases' => array(), 7 'aliases' => array(),
8 - 'reference' => 'cb9b0017c6c4e6f18f312b3d801ab0e018e91dd4', 8 + 'reference' => 'c3efdae528dee58ee64851b95c6cf847a28a095d',
9 'name' => 'karsonzhang/fastadmin', 9 'name' => 'karsonzhang/fastadmin',
10 'dev' => true, 10 'dev' => true,
11 ), 11 ),
@@ -1132,7 +1132,7 @@ @@ -1132,7 +1132,7 @@
1132 'type' => 'project', 1132 'type' => 'project',
1133 'install_path' => __DIR__ . '/../../', 1133 'install_path' => __DIR__ . '/../../',
1134 'aliases' => array(), 1134 'aliases' => array(),
1135 - 'reference' => 'cb9b0017c6c4e6f18f312b3d801ab0e018e91dd4', 1135 + 'reference' => 'c3efdae528dee58ee64851b95c6cf847a28a095d',
1136 'dev_requirement' => false, 1136 'dev_requirement' => false,
1137 ), 1137 ),
1138 'karsonzhang/fastadmin-addons' => array( 1138 'karsonzhang/fastadmin-addons' => array(
@@ -1279,6 +1279,15 @@ @@ -1279,6 +1279,15 @@
1279 'reference' => 'a94b3a4db7fb774b3d78dad2315ddc07629e1bed', 1279 'reference' => 'a94b3a4db7fb774b3d78dad2315ddc07629e1bed',
1280 'dev_requirement' => false, 1280 'dev_requirement' => false,
1281 ), 1281 ),
  1282 + 'predis/predis' => array(
  1283 + 'pretty_version' => 'v1.1.10',
  1284 + 'version' => '1.1.10.0',
  1285 + 'type' => 'library',
  1286 + 'install_path' => __DIR__ . '/../predis/predis',
  1287 + 'aliases' => array(),
  1288 + 'reference' => 'a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e',
  1289 + 'dev_requirement' => false,
  1290 + ),
1282 'psr/cache' => array( 1291 'psr/cache' => array(
1283 'pretty_version' => '1.0.1', 1292 'pretty_version' => '1.0.1',
1284 'version' => '1.0.1.0', 1293 'version' => '1.0.1.0',
  1 +v1.1.10 (2022-01-05)
  2 +================================================================================
  3 +
  4 +- __FIX__: Avoid PHP 8.1 deprecation notices in `Session/Handler`
  5 +- __FIX__: Fixed "Cannot use object of type Predis\Response\Error as array"
  6 +error in `Connection/Aggregate/SentinelReplication`
  7 +
  8 +
  9 +v1.1.9 (2021-10-05)
  10 +================================================================================
  11 +
  12 +- __FIX__: Fixed PHP 8.1 compatibility in `StreamConnection`
  13 +
  14 +
  15 +v1.1.8 (2021-09-29)
  16 +================================================================================
  17 +
  18 +- __FIX__: Ensure compatibility with PHP 8.1.
  19 +
  20 +
  21 +v1.1.7 (2021-04-04)
  22 +================================================================================
  23 +
  24 +- __FIX__: with the phpiredis-based connection backends, failed pipelines led to
  25 +spurious responses returned after reconnecting to Redis because the underlying
  26 +reader was not properly reset by discarding buffered replies after disconnecting
  27 +(ISSUE #363).
  28 +- __FIX__: removed `cweagans/composer-patches` dev dependency and apply patches
  29 +using `post-update-cmd` script.
  30 +
  31 +
  32 +v1.1.6 (2020-09-11)
  33 +================================================================================
  34 +
  35 +- __FIX__: reverted support for sentinels authentication implemented in v1.1.5
  36 +as it was bugged (see ISSUE #658), sorry for the trouble. This is now postponed
  37 +as it requires a more thorough investigation.
  38 +
  39 +
  40 +v1.1.5 (2020-09-10)
  41 +================================================================================
  42 +
  43 +- __FIX__:~~authentication for sentinels is now supported, previously it was not
  44 +possible to specify a `password` for sentinels as its value was stripped during
  45 +initialization because sentinels did not support authentication until Redis 5.
  46 +**Please note** that with the current implementation each sentinel must have
  47 +its own `password` parameter set in the parameters list despite this password is
  48 +the same for all sentinels (read how `requirepass` works on the Redis docs). In
  49 +this case you should avoid using the global `parameters` client option used to
  50 +set default parameters for every connection created by Predis as this would end
  51 +up using the same password even when connecting to actual Redis nodes.~~
  52 +
  53 +- __FIX__: the username is now correctly retrieved from the userinfo fragment of
  54 +the URI when using the "redis" scheme and a "username:password" pair is present.
  55 +Values retrieved from the userinfo fragment always override the ones specified
  56 +in `username` and `password` if those fields are present in the query string.
  57 +
  58 +- __FIX__: `Predis\Connection\WebdisConnection` was unable to connect to Webdis
  59 +when using an IPv4 address in the URL and this is probably due to some change in
  60 +cURL internals since the last time we tested it.
  61 +
  62 +- __FIX__: an exception is thrown whe passing `FALSE` or any value evaluating to
  63 +`FALSE` to the `replication` client option. This was supposed to be unsupported,
  64 +in fact it actually breaks client initialization and raises a PHP warning. Now
  65 +the user is alerted with an `InvalidArgumentException` and a proper message.
  66 +(PR #381).
  67 +
  68 +
  69 +v1.1.4 (2020-08-31)
  70 +================================================================================
  71 +
  72 +- Improved @method annotations for methods responding to Redis commands defined
  73 + by `Predis\ClientInterface` and `Predis\ClientContextInterface`. (PR #456 and
  74 + PR #497, other fixes applied after further analysys).
  75 +
  76 +- __FIX__: the client can now handle ACL authentication when connecting to Redis
  77 + 6.x simply by passing both `username` and `password` to connection parameters.
  78 + See [the Redis docs](https://redis.io/topics/acl) for details on this topic.
  79 +
  80 +- __FIX__: NULL or zero-length string values passed to `password` and `database`
  81 + in the connection parameters list do not trigger spurious `AUTH` and `SELECT`
  82 + commands anymore when connecting to Redis (ISSUE #436).
  83 +
  84 +- __FIX__: initializing an iteration over a client instance when it is connected
  85 + to a standalone Redis server will not throw an exception anymore, instead it
  86 + will return an iterator that will run for just one loop returning a new client
  87 + instance using the underlying single-node connection (ISSUE #552, PR #556).
  88 +
  89 +- __FIX__: `Predis\Cluster\Distributor\HashRingaddNodeToRing()` was calculating
  90 + the hash required for distribution by using `crc32()` directly instead of the
  91 + method `Predis\Cluster\Hash\HashGeneratorInterface::hash()` implemented by the
  92 + class itself. This bug fix does not have any impact on existing clusters that
  93 + use client-side sharding based on this distributor simply because it does not
  94 + take any external hash generators so distribution is not going to be affected.
  95 +
  96 +- __FIX__: `SORT` now always trigger a switch to the master node in replication
  97 + configurations instead of just when the `STORE` modifier is specified, this is
  98 + because `SORT` is always considered to be a write operation and actually fails
  99 + with a `-READONLY` error response when executed against a replica node. (ISSUE
  100 + #554).
  101 +
  102 +
  103 +v1.1.3 (2020-08-18)
  104 +================================================================================
  105 +
  106 +- Ensure compatibility with PHP 8.
  107 +
  108 +- Moved repository from `github.com/nrk/predis` to `github.com/predis/predis`.
  109 +
  110 +- __FIX__: Moved `cweagans/composer-patches` dependency to `require-dev`.
  111 +
  112 +- __FIX__: Include PHPUnit `.patch` files in exports.
  113 +
  114 +
  115 +v1.1.2 (2020-08-11)
  116 +================================================================================
  117 +
  118 +- __FIX__: pure CRC16 implementation failed to calculate the correct hash when
  119 + the input value passed to the `hash()` method is an integer (PR #450).
  120 +
  121 +- __FIX__: make PHP iterator abstractions for `ZSCAN` and `HSCAN` working with
  122 + PHP 7.2 due to a breaking change, namely the removal of `each()` (PR #448).
  123 +
  124 +
  125 +v1.1.1 (2016-06-16)
  126 +================================================================================
  127 +
  128 +- __FIX__: `password` and `database` from the global `parameters` client option
  129 + were still being applied to sentinels connections making them fail (sentinels
  130 + do not understand the `AUTH` and `SELECT` commands) (PR #346).
  131 +
  132 +- __FIX__: when a sentinel instance reports no sentinel for a service, invoking
  133 + `connect()` on the redis-sentinel connection backend should fall back to the
  134 + master connection instead of failing (ISSUE #342).
  135 +
  136 +- __FIX__: the two connection backends based on ext-phpiredis has some kind of
  137 + issues with the GC and the internal use of closures as reader callbacks that
  138 + prevented connections going out of scope from being properly collected and the
  139 + underlying stream or socket resources from being closed and freed. This should
  140 + not have had any actual effect in real-world scenarios due to the lifecycle of
  141 + PHP scripts, but we fixed it anyway (ISSUE #345).
  142 +
  143 +
  144 +v1.1.0 (2016-06-02)
  145 +================================================================================
  146 +
  147 +- The default server profile for the client now targets Redis 3.2.
  148 +
  149 +- Responses to the following commands are not casted into booleans anymore, the
  150 + original integer value is returned: `SETNX`, `MSETNX`, `SMOVE`, `SISMEMBER`,
  151 + `HSET`, `HSETNX`, `HEXISTS`, `PFADD`, `EXISTS`, `MOVE`, `PERSIST`, `EXPIRE`,
  152 + `EXPIREAT`, `RENAMENX`. This change does not have a significant impact unless
  153 + when using strict comparisons (=== and !==) the returned value.
  154 +
  155 +- Non-boolean string values passed to the `persistent` connection parameter can
  156 + be used to create different persistent connections. Note that this feature was
  157 + already present in Predis but required both `persistent` and `path` to be set
  158 + as illustrated by [#139](https://github.com/nrk/predis/pull/139). This change
  159 + is needed to prevent confusion with how `path` is used to select a database
  160 + when using the `redis` scheme.
  161 +
  162 +- The client throws exceptions when Redis returns any kind of error response to
  163 + initialization commands (the ones being automatically sent when a connection
  164 + is established, such as `SELECT` and `AUTH` when database and password are set
  165 + in connection parameters) regardless of the value of the exception option.
  166 +
  167 +- Using `unix:///path/to/socket` in URI strings to specify a UNIX domain socket
  168 + file is now deprecated in favor of the format `unix:/path/to/socket` (note the
  169 + lack of the double slash after the scheme) and will not be supported starting
  170 + with the next major release.
  171 +
  172 +- Implemented full support for redis-sentinel.
  173 +
  174 +- Implemented the ability to specify default connection parameters for aggregate
  175 + connections with the new `parameters` client option. These parameters augment
  176 + the usual user-supplied connection parameters (but do not take the precedence
  177 + over them) when creating new connections and they are mostly useful when the
  178 + client is using aggregate connections such as redis-cluster and redis-sentinel
  179 + as these backends can create new connections on the fly based on responses and
  180 + redirections from Redis.
  181 +
  182 +- Redis servers protected by SSL-encrypted connections can be accessed by using
  183 + the `tls` or `rediss` scheme in connection parameters along with SSL-specific
  184 + options in the `ssl` parameter (see http://php.net/manual/context.ssl.php).
  185 +
  186 +- `Predis\Client` implements `IteratorAggregate` making it possible to iterate
  187 + over traversable aggregate connections and get a new client instance for each
  188 + Redis node.
  189 +
  190 +- Iterating over an instance of `Predis\Connection\Aggregate\RedisCluster` will
  191 + return all the connections mapped in the slots map instead of just the ones in
  192 + the pool. This change makes it possible, when the slots map is retrieved from
  193 + Redis, to iterate over all of the master nodes in the cluster. When the use of
  194 + `CLUSTER SLOTS` is disabled via the `useClusterSlots()` method, the iteration
  195 + returns only the connections with slots ranges associated in their parameters
  196 + or the ones initialized by `-MOVED` responses in order to make the behaviour
  197 + of the iteration consistent between the two modes of operation.
  198 +
  199 +- Various improvements to `Predis\Connection\Aggregate\MasterSlaveReplication`
  200 + (the "basic" replication backend, not the new one based on redis-sentinel):
  201 +
  202 + - When the client is not able to send a read-only command to a slave because
  203 + the current connection fails or the slave is resyncing (`-LOADING` response
  204 + returned by Redis), the backend discards the failed connection and performs
  205 + a new attempt on the next slave. When no other slave is available the master
  206 + server is used for read-only commands as last resort.
  207 +
  208 + - It is possible to discover the current replication configuration on the fly
  209 + by invoking the `discover()` method which internally relies on the output of
  210 + the command `INFO REPLICATION` executed against the master server or one of
  211 + the slaves. The backend can also be configured to do this automatically when
  212 + it fails to reach one of the servers.
  213 +
  214 + - Implemented the `switchToMaster()` and `switchToSlave()` methods to make it
  215 + easier to force a switch to the master server or a random slave when needed.
  216 +
  217 +
  218 +v1.0.4 (2016-05-30)
  219 +================================================================================
  220 +
  221 +- Added new profile for Redis 3.2 with its new commands: `HSTRLEN`, `BITFIELD`,
  222 + `GEOADD`, `GEOHASH`, `GEOPOS`, `GEODIST`, `GEORADIUS`, `GEORADIUSBYMEMBER`.
  223 + The default server profile for Predis is still the one for Redis 3.0 you must
  224 + set the `profile` client option to `3.2` when initializing the client in order
  225 + to be able to use them when connecting to Redis 3.2.
  226 +
  227 +- Various improvements in the handling of redis-cluster:
  228 +
  229 + - If the connection to a specific node fails when executing a command, the
  230 + client tries to connect to another node in order to refresh the slots map
  231 + and perform a new attempt to execute the command.
  232 +
  233 + - Connections to nodes can be preassigned to non-contiguous slot ranges via
  234 + the `slots` parameter using a comma separator. This is how it looks like
  235 + in practice: `tcp://127.0.0.1:6379?slots=0-5460,5500-5600,11000`.
  236 +
  237 +- __FIX__: broken values returned by `Predis\Collection\Iterator\HashKey` when
  238 + iterating hash keys containing integer fields (PR #330, ISSUE #331).
  239 +
  240 +- __FIX__: prevent failures when `Predis\Connection\StreamConnection` serializes
  241 + commands with holes in their arguments (e.g. `[0 => 'key:0', 2 => 'key:2']`).
  242 + The same fix has been applied to `Predis\Protocol\Text\RequestSerializer`.
  243 + (ISSUE #316).
  244 +
  245 +
  246 +v1.0.3 (2015-07-30)
  247 +================================================================================
  248 +
  249 +- __FIX__: the previous release introduced a severe regression on HHVM that made
  250 + the library unable to connect to Redis when using IPv4 addresses. Code running
  251 + on the standard PHP interpreter is not affected.
  252 +
  253 +
  254 +v1.0.2 (2015-07-30)
  255 +================================================================================
  256 +
  257 +- IPv6 is now fully supported.
  258 +
  259 +- Added `redis` as an accepted scheme for connection parameters. When using this
  260 + scheme, the rules used to parse URI strings match the provisional registration
  261 + [published by IANA](http://www.iana.org/assignments/uri-schemes/prov/redis).
  262 +
  263 +- Added new or missing commands: `HSTRLEN` (>= 3.2), `ZREVRANGEBYLEX` (>= 2.8)
  264 + and `MIGRATE` (>= 2.6).
  265 +
  266 +- Implemented support for the `ZADD` modifiers `NX|XX`, `CH`, `INCR` (Redis >=
  267 + 3.0.2) using the simplified signature where scores and members are passed as
  268 + a named array.
  269 +
  270 +- __FIX__: `Predis\Configuration\Options` must not trigger the autoloader when
  271 + option values are strings (ISSUE #257).
  272 +
  273 +- __FIX__: `BITPOS` was not defined in the key-prefix processor (ISSUE #265) and
  274 + in the replication strategy.
  275 +
  276 +
  277 +v1.0.1 (2015-01-02)
  278 +================================================================================
  279 +
  280 +- Added `BITPOS` to the server profile for Redis 2.8.
  281 +
  282 +- Connection timeout for read/write operations can now be set for UNIX sockets
  283 + where the underlying connection uses PHP's stream.
  284 +
  285 +- __FIX__: broken values returned by `Predis\Collection\Iterator\SortedSetKey`
  286 + when iterating sorted set containing integer members (ISSUE #216).
  287 +
  288 +- __FIX__: applied a minor workaround for a bug in old versions of PHP < 5.3.9
  289 + affecting inheritance.
  290 +
  291 +- __FIX__: prevent E_NOTICE warnings when using INFO [section] returns an empty
  292 + response due to an unsupported specific set of information requested to Redis.
  293 +
  294 +
  295 +v1.0.0 (2014-08-01)
  296 +================================================================================
  297 +
  298 +- Switched to PSR-4 for autoloading.
  299 +
  300 +- The default server profile for Redis is `3.0`.
  301 +
  302 +- Removed server profile for Redis 1.2.
  303 +
  304 +- Added `SENTINEL` to the profile for Redis 2.6 and `PUBSUB` to the profile for
  305 + Redis 2.8.
  306 +
  307 +- `Predis\Client` can now send raw commands using `Predis\Client::executeRaw()`.
  308 +
  309 +- Status responses are returned as instances of `Predis\Response\Status`, for
  310 + example +OK is not returned as boolean TRUE anymore which is a breaking change
  311 + for those using strict comparisons. Status responses can be casted to string
  312 + values carrying the original payload, so one can do `$response == 'OK'` which
  313 + is also more akin to how Redis replies to clients.
  314 +
  315 +- Commands `ZRANGE`, `ZRANGEBYSCORE`, `ZREVRANGE` and `ZREVRANGEBYSCORE` using
  316 + `WITHSCORE` return a named array of member => score instead of using an array
  317 + of [member, score] elements. Insertion order is preserved anyway due to how
  318 + PHP works internally.
  319 +
  320 +- The command `ZSCAN` returns a named array of member => score instead of using
  321 + an array of [member, score] elements. Insertion order is preserved anyway due
  322 + to how PHP works internally.
  323 +
  324 +- The rules for redis-cluster are now leveraged for empty key tags when using
  325 + client-side sharding, which means that when one or the first occurrence of {}
  326 + is found in a key it will most likely produce a different hash than previous
  327 + versions of Predis thus leading to a different partitioning in these cases.
  328 +
  329 +- Invoking `Predis\Client::connect()` when the underlying connection has been
  330 + already established does not throw any exception anymore, now the connection
  331 + simply does not attempt to perform any operation.
  332 +
  333 +- Added the `aggregate` client option, useful to fully customize how the client
  334 + should aggregate multiple connections when an array of connection parameters
  335 + is passed to `Predis\Client::__construct()`.
  336 +
  337 +- Dropped support for streamable multibulk responses. Actually we still ship the
  338 + iterator response classes just in case anyone would want to build custom stuff
  339 + at a level lower than the client abstraction (our standard and composable text
  340 + protocol processors still handle them and can be used as an example).
  341 +
  342 +- Simplified the implementation of connection parameters by removing method used
  343 + to cast to int / bool / float certain parameters supplied by users. Casting
  344 + values, if deemed necessary, should be done by the consumer or you can just
  345 + subclass `Predis\Connection\Parameters` and override the `filter()` method.
  346 +
  347 +- Changed a couple of options for our transaction abstraction:
  348 +
  349 + - `exceptions`: overrides the value of the client option with the same name.
  350 + Please note that it does not affect all the transaction control commands
  351 + such as `MULTI`, `EXEC`, `DISCARD`, `WATCH` and `UNWATCH`.
  352 + - `on_retry`: this option has been removed.
  353 +
  354 +- Removed pipeline executors, now command pipelines can be easily customized by
  355 + extending the standard `Predis\Pipeline\Pipeline` class. Accepted options when
  356 + creating a pipeline using `Predis\Client::pipeline()` are:
  357 +
  358 + - `atomic`: returns a pipeline wrapped in a MULTI / EXEC transaction
  359 + (class: `Predis\Pipeline\Atomic`).
  360 + - `fire-and-forget`: returns a pipeline that does not read back responses
  361 + (class: `Predis\Pipeline\FireAndForget`).
  362 +
  363 +- Renamed the two base abstract command classes:
  364 +
  365 + - `Predis\Command\AbstractCommand` is now `Predis\Command\Command`
  366 + - `Predis\Command\ScriptedCommand` is now `Predis\Command\ScriptCommand`
  367 +
  368 +- Dropped `Predis\Command\Command::__toString()` (see issue #151).
  369 +
  370 +- The key prefixing logic has been moved from command classes to the key prefix
  371 + processor. Developers can define or override handlers used to prefix keys, but
  372 + they can also define the needed logic in their command classes by implementing
  373 + `Predis\Command\PrefixableCommandInterface` just like before.
  374 +
  375 +- `Predis\PubSub\DispatcherLoop` now takes a `Predis\PubSub\Consumer` instance
  376 + as the sole argument of its constructor instead of `Predis\ClientInterface`.
  377 +
  378 +- All of the interfaces and classes related to translated Redis response types
  379 + have been moved in the new `Predis\Response` namespace and most of them have
  380 + been renamed to make their fully-qualified name less redundant. Now the base
  381 + response interface is `Predis\Response\ResponseInterface`.
  382 +
  383 +- Renamed interface `Predis\Command\Processor\CommandProcessorInterface` to a
  384 + shorter `Predis\Command\Processor\ProcessorInterface`. Also removed interface
  385 + for chain processors since it is basically useless.
  386 +
  387 +- Renamed `Predis\ExecutableContextInterface` to `Predis\ClientContextInterface`
  388 + and augmented it with a couple of required methods since this interface is no
  389 + more comparable to a basic client as it could be misleading.
  390 +
  391 +- The `Predis\Option` namespace is now known as `Predis\Configuration` and have
  392 + a fully-reworked `Options` class with the ability to lazily initialize values
  393 + using objects that responds to `__invoke()` (not all the kinds of callables)
  394 + even for custom options defined by the user.
  395 +
  396 +- Renamed `Predis\Connection\ConnectionInterface::writeCommand()` into
  397 + `writeRequest()` for consistency with its counterpart, `readResponse()`.
  398 +
  399 +- Renamed `Predis\Connection\SingleConnectionInterface::pushInitCommand()` into
  400 + `addConnectCommand()` which is more obvious.
  401 +
  402 +- Renamed the connection class based on both ext-phpiredis and ext-socket into
  403 + `Predis\Connection\PhpiredisSocketConnection`. The one based on PHP's streams
  404 + is still named `Predis\Connection\PhpiredisStreamConnection`.
  405 +
  406 +- Renamed the connection factory class to `Predis\Connection\Factory`. Now its
  407 + constructor does not require anymore a profile instance to create `AUTH` and
  408 + `SELECT` commands when parameters contain both `password` and `database`. Raw
  409 + commands will be used instead.
  410 +
  411 +- Renamed the connection parameters class to `Predis\Connection\Parameters`. Now
  412 + its constructor accepts only named arrays, but instances can still be created
  413 + using both URIs or arrays using the static method `Parameters::create()`.
  414 +
  415 +- The profile factory code has been extracted from the abstract Redis profile
  416 + class and now lives in `Predis\Profile\Factory`.
  417 +
  418 +- The `Predis\Connection` namespace has been completely reorganized by renaming
  419 + a few classes and interfaces and adding some sub-namespaces.
  420 +
  421 +- Most classes and interfaces in the `Predis\Protocol` namespace have been moved
  422 + or renamed while rationalizing the whole API for external protocol processors.
  423 +
  424 +
  425 +v0.8.7 (2014-08-01)
  426 +================================================================================
  427 +
  428 +- Added `3.0` in the server profiles aliases list for Redis 3.0. `2.8` is still
  429 + the default server profile and `dev` still targets Redis 3.0.
  430 +
  431 +- Added `COMMAND` to the server profile for Redis 2.8.
  432 +
  433 +- Switched internally to the `CLUSTER SLOTS` command instead of `CLUSTER NODES`
  434 + to fetch the updated slots map from redis-cluster. This change requires users
  435 + to upgrade Redis nodes to >= 3.0.0b7.
  436 +
  437 +- The updated slots map is now fetched automatically from redis-cluster upon the
  438 + first `-MOVED` response by default. This change makes it possible to feed the
  439 + client constructor with only a few nodes of the actual cluster composition,
  440 + without needing a more complex configuration.
  441 +
  442 +- Implemented support for `PING` in PUB/SUB loop for Redis >= 3.0.0b8.
  443 +
  444 +- The default client-side sharding strategy and the one for redis-cluster now
  445 + share the same implementations as they follow the same rules. One difference,
  446 + aside from the different hashing function used to calculate distribution, is
  447 + in how empty hash tags like {} are treated by redis-cluster.
  448 +
  449 +- __FIX__: the patch applied to fix #180 introduced a regression affecting read/
  450 + write timeouts in `Predis\Connection\PhpiredisStreamConnection`. Unfortunately
  451 + the only possible solution requires PHP 5.4+. On PHP 5.3, read/write timeouts
  452 + will be ignored from now on.
  453 +
  454 +
  455 +v0.8.6 (2014-07-15)
  456 +================================================================================
  457 +
  458 +- Redis 2.8 is now the default server profile as there are no changes that would
  459 + break compatibility with previous releases.
  460 +
  461 +- Added `PFADD`, `PFCOUNT`, `PFMERGE` to the server profile for Redis 2.8 for
  462 + handling the HyperLogLog data structure introduced in Redis 2.8.9.
  463 +
  464 +- Added `ZLEXCOUNT`, `ZRANGEBYLEX`, `ZREMRANGEBYLEX` to the server profile for
  465 + Redis 2.8 for handling lexicographic operations on members of sorted sets.
  466 +
  467 +- Added support for key hash tags when using redis-cluster (Redis 3.0.0b1).
  468 +
  469 +- __FIX__: minor tweaks to make Predis compatible with HHVM >= 2.4.0.
  470 +
  471 +- __FIX__: responses to `INFO` are now properly parsed and will not break when
  472 + redis sentinel is being used (ISSUE #154).
  473 +
  474 +- __FIX__: added missing support for `INCRBYFLOAT` in cluster and replication
  475 + configurations (ISSUE #159).
  476 +
  477 +- __FIX__: fix parsing of the output of `CLUSTER NODES` to fetch the slots map
  478 + from a node when redis-cluster has slaves in its configuration (ISSUE #165).
  479 +
  480 +- __FIX__: prevent a stack overflow when iterating over large Redis collections
  481 + using our abstraction for cursor-based iterators (ISSUE #182).
  482 +
  483 +- __FIX__: properly discards transactions when the server immediately returns an
  484 + error response (e.g. -OOM or -ERR on invalid arguments for a command) instead
  485 + of a +QUEUED response (ISSUE #187).
  486 +
  487 +- Upgraded to PHPUnit 4.* for the test suite.
  488 +
  489 +
  490 +v0.8.5 (2014-01-16)
  491 +================================================================================
  492 +
  493 +- Added `2.8` in the server profiles aliases list for Redis 2.8. `2.6` is still
  494 + the default server profile and `dev` now targets Redis 3.0.
  495 +
  496 +- Added `SCAN`, `SSCAN`, `ZSCAN`, `HSCAN` to the server profile for Redis 2.8.
  497 +
  498 +- Implemented PHP iterators for incremental iterations over Redis collections:
  499 +
  500 + - keyspace (cursor-based iterator using `SCAN`)
  501 + - sets (cursor-based iterator using `SSCAN`)
  502 + - sorted sets (cursor-based iterator using `ZSCAN`)
  503 + - hashes (cursor-based iterator using `HSCAN`)
  504 + - lists (plain iterator using `LRANGE`)
  505 +
  506 +- It is now possible to execute "raw commands" using `Predis\Command\RawCommand`
  507 + and a variable list of command arguments. Input arguments are not filtered and
  508 + responses are not parsed, which means arguments must follow the signature of
  509 + the command as defined by Redis and complex responses are left untouched.
  510 +
  511 +- URI parsing for connection parameters has been improved and has slightly less
  512 + overhead when the number of fields in the querystring grows. New features are:
  513 +
  514 + - Parsing does not break when value of a field contains one or more "=".
  515 + - Repeated fieldnames using [] produce an array of values.
  516 + - Empty or incomplete "key=value" pairs result in an empty string for "key".
  517 +
  518 +- Various improvements and fixes to the redis-cluster connection backend:
  519 +
  520 + - __FIX__: the `ASKING` command is sent upon -ASK redirections.
  521 + - An updated slots-map can be fetched from nodes using the `CLUSTER NODES`
  522 + command. By default this is a manual operation but can be enabled to get
  523 + automatically done upon -MOVED redirections.
  524 + - It is possible to specify a common set of connection parameters that are
  525 + applied to connections created on the fly upon redirections to nodes not
  526 + part of the initial pool.
  527 +
  528 +- List of deprecated methods:
  529 +
  530 + - `Predis\Client::multiExec()`: superseded by `Predis\Client::transaction()`
  531 + and to be removed in the next major release.
  532 + - `Predis\Client::pubSub()`: superseded by `Predis\Client::pubSubLoop()` and
  533 + to be removed in the next major release. This change was needed due to the
  534 + recently introduced `PUBSUB` command in Redis 2.8.
  535 +
  536 +
  537 +v0.8.4 (2013-07-27)
  538 +================================================================================
  539 +
  540 +- Added `DUMP` and `RESTORE` to the server profile for Redis 2.6.
  541 +
  542 +- Connection exceptions now report basic host details in their messages.
  543 +
  544 +- Allow `Predis\Connection\PhpiredisConnection` to use a random IP when a host
  545 + actually has several IPs (ISSUE #116).
  546 +
  547 +- __FIX__: allow `HMSET` when using a cluster of Redis nodes with client-side
  548 + sharding or redis-cluster (ISSUE #106).
  549 +
  550 +- __FIX__: set `WITHSCORES` modifer for `ZRANGE`, `ZREVRANGE`, `ZRANGEBYSCORE`
  551 + and `ZREVRANGEBYSCORE` only when the options array passed to these commands
  552 + has `WITHSCORES` set to `true` (ISSUE #107).
  553 +
  554 +- __FIX__: scripted commands falling back from `EVALSHA` to `EVAL` resulted in
  555 + PHP errors when using a prefixed client (ISSUE #109).
  556 +
  557 +- __FIX__: `Predis\PubSub\DispatcherLoop` now works properly when using key
  558 + prefixing (ISSUE #114).
  559 +
  560 +
  561 +v0.8.3 (2013-02-18)
  562 +================================================================================
  563 +
  564 +- Added `CLIENT SETNAME` and `CLIENT GETNAME` (ISSUE #102).
  565 +
  566 +- Implemented the `Predis\Connection\PhpiredisStreamConnection` class using the
  567 + `phpiredis` extension like `Predis\Connection\PhpiredisStreamConnection`, but
  568 + without requiring the `socket` extension since it relies on PHP's streams.
  569 +
  570 +- Added support for the TCP_NODELAY flag via the `tcp_nodelay` parameter for
  571 + stream-based connections, namely `Predis\Connection\StreamConnection` and
  572 + `Predis\Connection\PhpiredisStreamConnection` (requires PHP >= 5.4.0).
  573 +
  574 +- Updated the aggregated connection class for redis-cluster to work with 16384
  575 + hash slots instead of 4096 to reflect the recent change from redis unstable
  576 + ([see this commit](https://github.com/antirez/redis/commit/ebd666d)).
  577 +
  578 +- The constructor of `Predis\Client` now accepts a callable as first argument
  579 + returning `Predis\Connection\ConnectionInterface`. Users can create their
  580 + own self-contained strategies to create and set up the underlying connection.
  581 +
  582 +- Users should return `0` from `Predis\Command\ScriptedCommand::getKeysCount()`
  583 + instead of `FALSE` to indicate that all of the arguments of a Lua script must
  584 + be used to populate `ARGV[]`. This does not represent a breaking change.
  585 +
  586 +- The `Predis\Helpers` class has been deprecated and it will be removed in
  587 + future releases.
  588 +
  589 +
  590 +v0.8.2 (2013-02-03)
  591 +================================================================================
  592 +
  593 +- Added `Predis\Session\SessionHandler` to make it easy to store PHP sessions
  594 + on Redis using Predis. Please note that this class needs either PHP >= 5.4.0
  595 + or a polyfill for PHP's `SessionHandlerInterface`.
  596 +
  597 +- Added the ability to get the default value of a client option directly from
  598 + `Predis\Option\ClientOption` using the `getDefault()` method by passing the
  599 + option name or its instance.
  600 +
  601 +- __FIX__: the standard pipeline executor was not using the response parser
  602 + methods associated to commands to process raw responses (ISSUE #101).
  603 +
  604 +
  605 +v0.8.1 (2013-01-19)
  606 +================================================================================
  607 +
  608 +- The `connections` client option can now accept a callable object returning
  609 + an instance of `Predis\Connection\ConnectionFactoryInterface`.
  610 +
  611 +- Client options accepting callable objects as factories now pass their actual
  612 + instance to the callable as the second argument.
  613 +
  614 +- `Predis\Command\Processor\KeyPrefixProcessor` can now be directly casted to
  615 + string to obtain the current prefix, useful with string interpolation.
  616 +
  617 +- Added an optional callable argument to `Predis\Cluster\Distribution\HashRing`
  618 + and `Predis\Cluster\Distribution\KetamaPureRing` constructor that can be used
  619 + to customize how the distributor should extract the connection hash when
  620 + initializing the nodes distribution (ISSUE #36).
  621 +
  622 +- Correctly handle `TTL` and `PTTL` returning -2 on non existing keys starting
  623 + with Redis 2.8.
  624 +
  625 +- __FIX__: a missing use directive in `Predis\Transaction\MultiExecContext`
  626 + caused PHP errors when Redis did not return `+QUEUED` replies to commands
  627 + when inside a MULTI / EXEC context.
  628 +
  629 +- __FIX__: the `parseResponse()` method implemented for a scripted command was
  630 + ignored when retrying to execute a Lua script by falling back to `EVAL` after
  631 + a `-NOSCRIPT` error (ISSUE #94).
  632 +
  633 +- __FIX__: when subclassing `Predis\Client` the `getClientFor()` method returns
  634 + a new instance of the subclass instead of a new instance of `Predis\Client`.
  635 +
  636 +
  637 +v0.8.0 (2012-10-23)
  638 +================================================================================
  639 +
  640 +- The default server profile for Redis is now `2.6`.
  641 +
  642 +- Certain connection parameters have been renamed:
  643 +
  644 + - `connection_async` is now `async_connect`
  645 + - `connection_timeout` is now `timeout`
  646 + - `connection_persistent` is now `persistent`
  647 +
  648 +- The `throw_errors` connection parameter has been removed and replaced by the
  649 + new `exceptions` client option since exceptions on `-ERR` replies returned by
  650 + Redis are not generated by connection classes anymore but instead are thrown
  651 + by the client class and other abstractions such as pipeline contexts.
  652 +
  653 +- Added smart support for redis-cluster (Redis v3.0) in addition to the usual
  654 + cluster implementation that uses client-side sharding.
  655 +
  656 +- Various namespaces and classes have been renamed to follow rules inspired by
  657 + the Symfony2 naming conventions.
  658 +
  659 +- The second argument of the constructor of `Predis\Client` does not accept
  660 + strings or instances of `Predis\Profile\ServerProfileInterface` anymore.
  661 + To specify a server profile you must explicitly set `profile` in the array
  662 + of client options.
  663 +
  664 +- `Predis\Command\ScriptedCommand` internally relies on `EVALSHA` instead of
  665 + `EVAL` thus avoiding to send Lua scripts bodies on each request. The client
  666 + automatically resends the command falling back to `EVAL` when Redis returns a
  667 + `-NOSCRIPT` error. Automatic fallback to `EVAL` does not work with pipelines,
  668 + inside a `MULTI / EXEC` context or with plain `EVALSHA` commands.
  669 +
  670 +- Complex responses are no more parsed by connection classes as they must be
  671 + processed by consumer classes using the handler associated to the issued
  672 + command. This means that executing commands directly on connections only
  673 + returns simple Redis types, but nothing changes when using `Predis\Client`
  674 + or the provided abstractions for pipelines and transactions.
  675 +
  676 +- Iterators for multi-bulk replies now skip the response parsing method of the
  677 + command that generated the response and are passed directly to user code.
  678 + Pipeline and transaction objects still consume automatically iterators.
  679 +
  680 +- Cluster and replication connections now extend a new common interface,
  681 + `Predis\Connection\AggregatedConnectionInterface`.
  682 +
  683 +- `Predis\Connection\MasterSlaveReplication` now uses an external strategy
  684 + class to handle the logic for checking readable / writable commands and Lua
  685 + scripts.
  686 +
  687 +- Command pipelines have been optimized for both speed and code cleanness, but
  688 + at the cost of bringing a breaking change in the signature of the interface
  689 + for pipeline executors.
  690 +
  691 +- Added a new pipeline executor that sends commands wrapped in a MULTI / EXEC
  692 + context to make the execution atomic: if a pipeline fails at a certain point
  693 + then the whole pipeline is discarded.
  694 +
  695 +- The key-hashing mechanism for commands is now handled externally and is no
  696 + more a competence of each command class. This change is neeeded to support
  697 + both client-side sharding and Redis cluster.
  698 +
  699 +- `Predis\Options\Option` is now abstract, see `Predis\Option\AbstractOption`.
  700 +
  701 +
  702 +v0.7.3 (2012-06-01)
  703 +================================================================================
  704 +
  705 +- New commands available in the Redis v2.6 profile (dev): `BITOP`, `BITCOUNT`.
  706 +
  707 +- When the number of keys `Predis\Commands\ScriptedCommand` is negative, Predis
  708 + will count from the end of the arguments list to calculate the actual number
  709 + of keys that will be interpreted as elements for `KEYS` by the underlying
  710 + `EVAL` command.
  711 +
  712 +- __FIX__: `examples\CustomDistributionStrategy.php` had a mistyped constructor
  713 + call and produced a bad distribution due to an error as pointed in ISSUE #63.
  714 + This bug is limited to the above mentioned example and does not affect the
  715 + classes implemented in the `Predis\Distribution` namespace.
  716 +
  717 +- __FIX__: `Predis\Commands\ServerEvalSHA::getScriptHash()` was calculating the
  718 + hash while it just needs to return the first argument of the command.
  719 +
  720 +- __FIX__: `Predis\Autoloader` has been modified to allow cascading autoloaders
  721 + for the `Predis` namespace.
  722 +
  723 +
  724 +v0.7.2 (2012-04-01)
  725 +================================================================================
  726 +
  727 +- Added `2.6` in the server profiles aliases list for the upcoming Redis 2.6.
  728 + `2.4` is still the default server profile. `dev` now targets Redis 2.8.
  729 +
  730 +- Connection instances can be serialized and unserialized using `serialize()`
  731 + and `unserialize()`. This is handy in certain scenarios such as client-side
  732 + clustering or replication to lower the overhead of initializing a connection
  733 + object with many sub-connections since unserializing them can be up to 5x
  734 + times faster.
  735 +
  736 +- Reworked the default autoloader to make it faster. It is also possible to
  737 + prepend it in PHP's autoload stack.
  738 +
  739 +- __FIX__: fixed parsing of the payload returned by `MONITOR` with Redis 2.6.
  740 +
  741 +
  742 +v0.7.1 (2011-12-27)
  743 +================================================================================
  744 +
  745 +- The PEAR channel on PearHub has been deprecated in favour of `pear.nrk.io`.
  746 +
  747 +- Miscellaneous minor fixes.
  748 +
  749 +- Added transparent support for master / slave replication configurations where
  750 + write operations are performed on the master server and read operations are
  751 + routed to one of the slaves. Please refer to ISSUE #21 for a bit of history
  752 + and more details about replication support in Predis.
  753 +
  754 +- The `profile` client option now accepts a callable object used to initialize
  755 + a new instance of `Predis\Profiles\IServerProfile`.
  756 +
  757 +- Exposed a method for MULTI / EXEC contexts that adds the ability to execute
  758 + instances of Redis commands against transaction objects.
  759 +
  760 +
  761 +v0.7.0 (2011-12-11)
  762 +================================================================================
  763 +
  764 +- Predis now adheres to the PSR-0 standard which means that there is no more a
  765 + single file holding all the classes of the library, but multiple files (one
  766 + for each class). You can use any PSR-0 compatible autoloader to load Predis
  767 + or just leverage the default one shipped with the library by requiring the
  768 + `Predis/Autoloader.php` and call `Predis\Autoloader::register()`.
  769 +
  770 +- The default server profile for Redis is now 2.4. The `dev` profile supports
  771 + all the features of Redis 2.6 (currently unstable) such as Lua scripting.
  772 +
  773 +- Support for long aliases (method names) for Redis commands has been dropped.
  774 +
  775 +- Redis 1.0 is no more supported. From now on Predis will use only the unified
  776 + protocol to serialize commands.
  777 +
  778 +- It is possible to prefix keys transparently on a client-level basis with the
  779 + new `prefix` client option.
  780 +
  781 +- An external connection factory is used to initialize new connection instances
  782 + and developers can now register their own connection classes using the new
  783 + `connections` client option.
  784 +
  785 +- It is possible to connect locally to Redis using UNIX domain sockets. Just
  786 + use `unix:///path/to/redis.sock` or a named array just like in the following
  787 + example: `array('scheme' => 'unix', 'path' => '/path/to/redis.sock');`.
  788 +
  789 +- If the `phpiredis` extension is loaded by PHP, it is now possible to use an
  790 + alternative connection class that leverages it to make Predis faster on many
  791 + cases, especially when dealing with big multibulk replies, with the the only
  792 + downside that persistent connections are not supported. Please refer to the
  793 + documentation to see how to activate this class using the new `connections`
  794 + client option.
  795 +
  796 +- Predis is capable to talk with Webdis, albeit with some limitations such as
  797 + the lack of pipelining and transactions, just by using the `http` scheme in
  798 + in the connection parameters. All is needed is PHP with the `curl` and the
  799 + `phpiredis` extensions loaded.
  800 +
  801 +- Way too many changes in the public API to make a list here, we just tried to
  802 + make all the Redis commands compatible with previous releases of v0.6 so that
  803 + you do not have to worry if you are simply using Predis as a client. Probably
  804 + the only breaking changes that should be mentioned here are:
  805 +
  806 + - `throw_on_error` has been renamed to `throw_errors` and it is a connection
  807 + parameter instead of a client option, along with `iterable_multibulk`.
  808 +
  809 + - `key_distribution` has been removed from the client options. To customize
  810 + the distribution strategy you must provide a callable object to the new
  811 + `cluster` client option to configure and then return a new instance of
  812 + `Predis\Network\IConnectionCluster`.
  813 +
  814 + - `Predis\Client::create()` has been removed. Just use the constructor to set
  815 + up a new instance of `Predis\Client`.
  816 +
  817 + - `Predis\Client::pipelineSafe()` was deprecated in Predis v0.6.1 and now has
  818 + finally removed. Use `Predis\Client::pipeline(array('safe' => true))`.
  819 +
  820 + - `Predis\Client::rawCommand()` has been removed due to inconsistencies with
  821 + the underlying connection abstractions. You can still get the raw resource
  822 + out of a connection with `Predis\Network\IConnectionSingle::getResource()`
  823 + so that you can talk directly with Redis.
  824 +
  825 +- The `Predis\MultiBulkCommand` class has been merged into `Predis\Command` and
  826 + thus removed. Serialization of commands is now a competence of connections.
  827 +
  828 +- The `Predis\IConnection` interface has been splitted into two new interfaces:
  829 + `Predis\Network\IConnectionSingle` and `Predis\Network\IConnectionCluster`.
  830 +
  831 +- The constructor of `Predis\Client` now accepts more type of arguments such as
  832 + instances of `Predis\IConnectionParameters` and `Predis\Network\IConnection`.
  833 +
  834 +
  835 +v0.6.6 (2011-04-01)
  836 +================================================================================
  837 +
  838 +- Switched to Redis 2.2 as the default server profile (there are no changes
  839 + that would break compatibility with previous releases). Long command names
  840 + are no more supported by default but if you need them you can still require
  841 + `Predis_Compatibility.php` to avoid breaking compatibility.
  842 +
  843 +- Added a `VERSION` constant to `Predis\Client`.
  844 +
  845 +- Some performance improvements for multibulk replies (parsing them is about
  846 + 16% faster than the previous version). A few core classes have been heavily
  847 + optimized to reduce overhead when creating new instances.
  848 +
  849 +- Predis now uses by default a new protocol reader, more lightweight and
  850 + faster than the default handler-based one. Users can revert to the old
  851 + protocol reader with the `reader` client option set to `composable`.
  852 + This client option can also accept custom reader classes implementing the
  853 + new `Predis\IResponseReader` interface.
  854 +
  855 +- Added support for connecting to Redis using UNIX domain sockets (ISSUE #25).
  856 +
  857 +- The `read_write_timeout` connection parameter can now be set to 0 or false
  858 + to disable read and write timeouts on connections. The old behaviour of -1
  859 + is still intact.
  860 +
  861 +- `ZUNIONSTORE` and `ZINTERSTORE` can accept an array to specify a list of the
  862 + source keys to be used to populate the destination key.
  863 +
  864 +- `MGET`, `SINTER`, `SUNION` and `SDIFF` can accept an array to specify a list
  865 + of keys. `SINTERSTORE`, `SUNIONSTORE` and `SDIFFSTORE` can also accept an
  866 + array to specify the list of source keys.
  867 +
  868 +- `SUBSCRIBE` and `PSUBSCRIBE` can accept a list of channels for subscription.
  869 +
  870 +- __FIX__: some client-side clean-ups for `MULTI/EXEC` were handled incorrectly
  871 + in a couple of corner cases (ISSUE #27).
  872 +
  873 +
  874 +v0.6.5 (2011-02-12)
  875 +================================================================================
  876 +
  877 +- __FIX__: due to an untested internal change introduced in v0.6.4, a wrong
  878 + handling of bulk reads of zero-length values was producing protocol
  879 + desynchronization errors (ISSUE #20).
  880 +
  881 +
  882 +v0.6.4 (2011-02-12)
  883 +================================================================================
  884 +
  885 +- Various performance improvements (15% ~ 25%) especially when dealing with
  886 + long multibulk replies or when using clustered connections.
  887 +
  888 +- Added the `on_retry` option to `Predis\MultiExecBlock` that can be used to
  889 + specify an external callback (or any callable object) that gets invoked
  890 + whenever a transaction is aborted by the server.
  891 +
  892 +- Added inline (p)subscribtion via options when initializing an instance of
  893 + `Predis\PubSubContext`.
  894 +
  895 +
  896 +v0.6.3 (2011-01-01)
  897 +================================================================================
  898 +
  899 +- New commands available in the Redis v2.2 profile (dev):
  900 + - Strings: `SETRANGE`, `GETRANGE`, `SETBIT`, `GETBIT`
  901 + - Lists : `BRPOPLPUSH`
  902 +
  903 +- The abstraction for `MULTI/EXEC` transactions has been dramatically improved
  904 + by providing support for check-and-set (CAS) operations when using Redis >=
  905 + 2.2. Aborted transactions can also be optionally replayed in automatic up
  906 + to a user-defined number of times, after which a `Predis\AbortedMultiExec`
  907 + exception is thrown.
  908 +
  909 +
  910 +v0.6.2 (2010-11-28)
  911 +================================================================================
  912 +
  913 +- Minor internal improvements and clean ups.
  914 +
  915 +- New commands available in the Redis v2.2 profile (dev):
  916 + - Strings: `STRLEN`
  917 + - Lists : `LINSERT`, `RPUSHX`, `LPUSHX`
  918 + - ZSets : `ZREVRANGEBYSCORE`
  919 + - Misc. : `PERSIST`
  920 +
  921 +- WATCH also accepts a single array parameter with the keys that should be
  922 + monitored during a transaction.
  923 +
  924 +- Improved the behaviour of `Predis\MultiExecBlock` in certain corner cases.
  925 +
  926 +- Improved parameters checking for the SORT command.
  927 +
  928 +- __FIX__: the `STORE` parameter for the `SORT` command didn't work correctly
  929 + when using `0` as the target key (ISSUE #13).
  930 +
  931 +- __FIX__: the methods for `UNWATCH` and `DISCARD` do not break anymore method
  932 + chaining with `Predis\MultiExecBlock`.
  933 +
  934 +
  935 +v0.6.1 (2010-07-11)
  936 +================================================================================
  937 +
  938 +- Minor internal improvements and clean ups.
  939 +
  940 +- New commands available in the Redis v2.2 profile (dev):
  941 + - Misc. : `WATCH`, `UNWATCH`
  942 +
  943 +- Optional modifiers for `ZRANGE`, `ZREVRANGE` and `ZRANGEBYSCORE` queries are
  944 + supported using an associative array passed as the last argument of their
  945 + respective methods.
  946 +
  947 +- The `LIMIT` modifier for `ZRANGEBYSCORE` can be specified using either:
  948 + - an indexed array: `array($offset, $count)`
  949 + - an associative array: `array('offset' => $offset, 'count' => $count)`
  950 +
  951 +- The method `Predis\Client::__construct()` now accepts also instances of
  952 + `Predis\ConnectionParameters`.
  953 +
  954 +- `Predis\MultiExecBlock` and `Predis\PubSubContext` now throw an exception
  955 + when trying to create their instances using a profile that does not
  956 + support the required Redis commands or when the client is connected to
  957 + a cluster of connections.
  958 +
  959 +- Various improvements to `Predis\MultiExecBlock`:
  960 + - fixes and more consistent behaviour across various usage cases.
  961 + - support for `WATCH` and `UNWATCH` when using the current development
  962 + profile (Redis v2.2) and aborted transactions.
  963 +
  964 +- New signature for `Predis\Client::multiExec()` which is now able to accept
  965 + an array of options for the underlying instance of `Predis\MultiExecBlock`.
  966 + Backwards compatibility with previous releases of Predis is ensured.
  967 +
  968 +- New signature for `Predis\Client::pipeline()` which is now able to accept
  969 + an array of options for the underlying instance of Predis\CommandPipeline.
  970 + Backwards compatibility with previous releases of Predis is ensured.
  971 + The method `Predis\Client::pipelineSafe()` is to be considered deprecated.
  972 +
  973 +- __FIX__: The `WEIGHT` modifier for `ZUNIONSTORE` and `ZINTERSTORE` was
  974 + handled incorrectly with more than two weights specified.
  975 +
  976 +
  977 +v0.6.0 (2010-05-24)
  978 +================================================================================
  979 +
  980 +- Switched to the new multi-bulk request protocol for all of the commands
  981 + in the Redis 1.2 and Redis 2.0 profiles. Inline and bulk requests are now
  982 + deprecated as they will be removed in future releases of Redis.
  983 +
  984 +- The default server profile is `2.0` (targeting Redis 2.0.x). If you are
  985 + using older versions of Redis, it is highly recommended that you specify
  986 + which server profile the client should use (e.g. `1.2` when connecting
  987 + to instances of Redis 1.2.x).
  988 +
  989 +- Support for Redis 1.0 is now optional and it is provided by requiring
  990 + 'Predis_Compatibility.php' before creating an instance of `Predis\Client`.
  991 +
  992 +- New commands added to the Redis 2.0 profile since Predis 0.5.1:
  993 + - Strings: `SETEX`, `APPEND`, `SUBSTR`
  994 + - ZSets : `ZCOUNT`, `ZRANK`, `ZUNIONSTORE`, `ZINTERSTORE`, `ZREMBYRANK`,
  995 + `ZREVRANK`
  996 + - Hashes : `HSET`, `HSETNX`, `HMSET`, `HINCRBY`, `HGET`, `HMGET`, `HDEL`,
  997 + `HEXISTS`, `HLEN`, `HKEYS`, `HVALS`, `HGETALL`
  998 + - PubSub : `PUBLISH`, `SUBSCRIBE`, `UNSUBSCRIBE`
  999 + - Misc. : `DISCARD`, `CONFIG`
  1000 +
  1001 +- Introduced client-level options with the new `Predis\ClientOptions` class.
  1002 + Options can be passed to the constructor of `Predis\Client` in its second
  1003 + argument as an array or an instance of `Predis\ClientOptions`. For brevity's
  1004 + sake and compatibility with older versions, the constructor still accepts
  1005 + an instance of `Predis\RedisServerProfile` in its second argument. The
  1006 + currently supported client options are:
  1007 +
  1008 + - `profile` [default: `2.0` as of Predis 0.6.0]: specifies which server
  1009 + profile to use when connecting to Redis. This option accepts an instance
  1010 + of `Predis\RedisServerProfile` or a string that indicates the version.
  1011 +
  1012 + - `key_distribution` [default: `Predis\Distribution\HashRing`]: specifies
  1013 + which key distribution strategy to use to distribute keys among the
  1014 + servers that compose a cluster. This option accepts an instance of
  1015 + `Predis\Distribution\IDistributionStrategy` so that users can implement
  1016 + their own key distribution strategy. `Predis\Distribution\KetamaPureRing`
  1017 + is an alternative distribution strategy providing a pure-PHP implementation
  1018 + of the same algorithm used by libketama.
  1019 +
  1020 + - `throw_on_error` [default: `TRUE`]: server errors can optionally be handled
  1021 + "silently": instead of throwing an exception, the client returns an error
  1022 + response type.
  1023 +
  1024 + - `iterable_multibulk` [EXPERIMENTAL - default: `FALSE`]: in addition to the
  1025 + classic way of fetching a whole multibulk reply into an array, the client
  1026 + can now optionally stream a multibulk reply down to the user code by using
  1027 + PHP iterators. It is just a little bit slower, but it can save a lot of
  1028 + memory in certain scenarios.
  1029 +
  1030 +- New parameters for connections:
  1031 +
  1032 + - `alias` [default: not set]: every connection can now be identified by an
  1033 + alias that is useful to get a specific connections when connected to a
  1034 + cluster of Redis servers.
  1035 + - `weight` [default: not set]: allows to balance keys asymmetrically across
  1036 + multiple servers. This is useful when you have servers with different
  1037 + amounts of memory to distribute the load of your keys accordingly.
  1038 + - `connection_async` [default: `FALSE`]: estabilish connections to servers
  1039 + in a non-blocking way, so that the client is not blocked while the socket
  1040 + resource performs the actual connection.
  1041 + - `connection_persistent` [default: `FALSE`]: the underlying socket resource
  1042 + is left open when a script ends its lifecycle. Persistent connections can
  1043 + lead to unpredictable or strange behaviours, so they should be used with
  1044 + extreme care.
  1045 +
  1046 +- Introduced the `Predis\Pipeline\IPipelineExecutor` interface. Classes that
  1047 + implements this interface are used internally by the `Predis\CommandPipeline`
  1048 + class to change the behaviour of the pipeline when writing/reading commands
  1049 + from one or multiple servers. Here is the list of the default executors:
  1050 +
  1051 + - `Predis\Pipeline\StandardExecutor`: exceptions generated by server errors
  1052 + might be thrown depending on the options passed to the client (see the
  1053 + `throw_on_error` client option). Instead, protocol or network errors always
  1054 + throw exceptions. This is the default executor for single and clustered
  1055 + connections and shares the same behaviour of Predis 0.5.x.
  1056 + - `Predis\Pipeline\SafeExecutor`: exceptions generated by server, protocol
  1057 + or network errors are not thrown but returned in the response array as
  1058 + instances of `Predis\ResponseError` or `Predis\CommunicationException`.
  1059 + - `Predis\Pipeline\SafeClusterExecutor`: this executor shares the same
  1060 + behaviour of `Predis\Pipeline\SafeExecutor` but it is geared towards
  1061 + clustered connections.
  1062 +
  1063 +- Support for PUB/SUB is handled by the new `Predis\PubSubContext` class, which
  1064 + could also be used to build a callback dispatcher for PUB/SUB scenarios.
  1065 +
  1066 +- When connected to a cluster of connections, it is now possible to get a
  1067 + new `Predis\Client` instance for a single connection of the cluster by
  1068 + passing its alias/index to the new `Predis\Client::getClientFor()` method.
  1069 +
  1070 +- `Predis\CommandPipeline` and `Predis\MultiExecBlock` return their instances
  1071 + when invokink commands, thus allowing method chaining in pipelines and
  1072 + multi-exec blocks.
  1073 +
  1074 +- `Predis\MultiExecBlock` can handle the new `DISCARD` command.
  1075 +
  1076 +- Connections now support float values for the `connection_timeout` parameter
  1077 + to express timeouts with a microsecond resolution.
  1078 +
  1079 +- __FIX__: TCP connections now respect the read/write timeout parameter when
  1080 + reading the payload of server responses. Previously, `stream_get_contents()`
  1081 + was being used internally to read data from a connection but it looks like
  1082 + PHP does not honour the specified timeout for socket streams when inside
  1083 + this function.
  1084 +
  1085 +- __FIX__: The `GET` parameter for the `SORT` command now accepts also multiple
  1086 + key patterns by passing an array of strings. (ISSUE #1).
  1087 +
  1088 +* __FIX__: Replies to the `DEL` command return the number of elements deleted
  1089 + by the server and not 0 or 1 interpreted as a boolean response. (ISSUE #4).
  1090 +
  1091 +
  1092 +v0.5.1 (2010-01-23)
  1093 +================================================================================
  1094 +
  1095 +* `RPOPLPUSH` has been changed from bulk command to inline command in Redis
  1096 + 1.2.1, so `ListPopLastPushHead` now extends `InlineCommand`. The old behavior
  1097 + is still available via the `ListPopLastPushHeadBulk` class so that you can
  1098 + override the server profile if you need the old (and uncorrect) behaviour
  1099 + when connecting to a Redis 1.2.0 instance.
  1100 +
  1101 +* Added missing support for `BGREWRITEAOF` for Redis >= 1.2.0.
  1102 +
  1103 +* Implemented a factory method for the `RedisServerProfile` class to ease the
  1104 + creation of new server profile instances based on a version string.
  1105 +
  1106 +
  1107 +v0.5.0 (2010-01-09)
  1108 +================================================================================
  1109 +* First versioned release of Predis
  1 +## Filing bug reports ##
  2 +
  3 +Bugs or feature requests can be posted on the [GitHub issues](http://github.com/predis/predis/issues)
  4 +section of the project.
  5 +
  6 +When reporting bugs, in addition to the obvious description of your issue you __must__ always provide
  7 +some essential information about your environment such as:
  8 +
  9 + 1. version of Predis (check the `VERSION` file or the `Predis\Client::VERSION` constant).
  10 + 2. version of Redis (check `redis_version` returned by [`INFO`](http://redis.io/commands/info)).
  11 + 3. version of PHP.
  12 + 4. name and version of the operating system.
  13 + 5. when possible, a small snippet of code that reproduces the issue.
  14 +
  15 +__Think about it__: we do not have a crystal ball and cannot predict things or peer into the unknown
  16 +so please provide as much details as possible to help us isolating issues and fix them.
  17 +
  18 +__Never__ use GitHub issues to post generic questions about Predis! When you have questions about
  19 +how Predis works or how it can be used, please just hop me an email and I will get back to you as
  20 +soon as possible.
  21 +
  22 +
  23 +## Contributing code ##
  24 +
  25 +If you want to work on Predis, it is highly recommended that you first run the test suite in order
  26 +to check that everything is OK and report strange behaviours or bugs. When modifying Predis please
  27 +make sure that no warnings or notices are emitted by PHP running the interpreter in your development
  28 +environment with the `error_reporting` variable set to `E_ALL | E_STRICT`.
  29 +
  30 +The recommended way to contribute to Predis is to fork the project on GitHub, create topic branches
  31 +on your newly created repository to fix bugs or add new features (possibly with tests covering your
  32 +modifications) and then open a pull request with a description of the applied changes. Obviously you
  33 +can use any other Git hosting provider of your preference.
  34 +
  35 +We always aim for consistency in our code base so you should follow basic coding rules as defined by
  36 +[PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md)
  37 +and [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)
  38 +and stick with the conventions used in Predis to name classes and interfaces. Indentation should be
  39 +done with 4 spaces and code should be wrapped at 100 columns (please try to stay within this limit
  40 +even if the above mentioned official coding guidelines set the soft limit to 120 columns).
  41 +
  42 +Please follow these [commit guidelines](http://git-scm.com/book/ch5-2.html#Commit-Guidelines) when
  43 +committing your code to Git and always write a meaningful (not necessarily extended) description of
  44 +your changes before opening pull requests.
  1 +# Some frequently asked questions about Predis #
  2 +________________________________________________
  3 +
  4 +### What is the point of Predis? ###
  5 +
  6 +The main point of Predis is about offering a highly customizable and extensible client for Redis,
  7 +that can be easily extended by developers while still being reasonabily fast. With Predis you can
  8 +swap almost any class with your own custom implementation: you can have custom connection classes,
  9 +new distribution strategies for client-side sharding, or handlers to replace or add Redis commands.
  10 +All of this can be achieved without messing with the source code of the library and directly in your
  11 +own application. Given the fast pace at which Redis is developed and adds new features, this can be
  12 +a great asset since it allows developers to add new and still missing features or commands or change
  13 +the standard behaviour of the library without the need to break dependencies in production code (at
  14 +least to some degree).
  15 +
  16 +### Does Predis support UNIX domain sockets and persistent connections? ###
  17 +
  18 +Yes. Obviously persistent connections actually work only when using PHP configured as a persistent
  19 +process reused by the web server (see [PHP-FPM](http://php-fpm.org)).
  20 +
  21 +### Does Predis support SSL-encrypted connections? ###
  22 +
  23 +Yes. Encrypted connections are mostly useful when connecting to Redis instances exposed by various
  24 +cloud hosting providers without the need to configure an SSL proxy, but you should also take into
  25 +account the general performances degradation especially during the connect() operation when the TLS
  26 +handshake must be performed to secure the connection. Persistent SSL-encrypted connections may help
  27 +in that respect, but they are supported only when running on PHP >= 7.0.0.
  28 +
  29 +### Does Predis support transparent (de)serialization of values? ###
  30 +
  31 +No and it will not ever do that by default. The reason behind this decision is that serialization is
  32 +usually something that developers prefer to customize depending on their needs and can not be easily
  33 +generalized when using Redis because of the many possible access patterns for your data. This does
  34 +not mean that it is impossible to have such a feature since you can leverage the extensibility of
  35 +this library to define your own serialization-aware commands. You can find more details about how to
  36 +do that [on this issue](http://github.com/predis/predis/issues/29#issuecomment-1202624).
  37 +
  38 +### How can I force Predis to connect to Redis before sending any command? ###
  39 +
  40 +Explicitly connecting to Redis is usually not needed since the client initializes connections lazily
  41 +only when they are needed. Admittedly, this behavior can be inconvenient in certain scenarios when
  42 +you absolutely need to perform an upfront check to determine if the server is up and running and
  43 +eventually catch exceptions on failures. Forcing the client to open the underlying connection can be
  44 +done by invoking `Predis\Client::connect()`:
  45 +
  46 +```php
  47 +$client = new Predis\Client();
  48 +
  49 +try {
  50 + $client->connect();
  51 +} catch (Predis\Connection\ConnectionException $exception) {
  52 + // We could not connect to Redis! Your handling code goes here.
  53 +}
  54 +
  55 +$client->info();
  56 +```
  57 +
  58 +### How Predis abstracts Redis commands? ###
  59 +
  60 +The approach used to implement Redis commands is quite simple: by default each command follows the
  61 +same signature as defined on the [Redis documentation](http://redis.io/commands) which makes things
  62 +pretty easy if you already know how Redis works or you need to look up how to use certain commands.
  63 +Alternatively, variadic commands can accept an array for keys or values (depending on the command)
  64 +instead of a list of arguments. Commands such as [`RPUSH`](http://redis.io/commands/rpush) and
  65 +[`HMSET`](http://redis.io/commands/hmset) are great examples:
  66 +
  67 +```php
  68 +$client->rpush('my:list', 'value1', 'value2', 'value3'); // plain method arguments
  69 +$client->rpush('my:list', ['value1', 'value2', 'value3']); // single argument array
  70 +
  71 +$client->hmset('my:hash', 'field1', 'value1', 'field2', 'value2'); // plain method arguments
  72 +$client->hmset('my:hash', ['field1'=>'value1', 'field2'=>'value2']); // single named array
  73 +```
  74 +
  75 +An exception to this rule is [`SORT`](http://redis.io/commands/sort) for which modifiers are passed
  76 +[using a named array](tests/Predis/Command/KeySortTest.php#L54-L75).
  77 +
  78 +
  79 +# Speaking about performances... #
  80 +_________________________________________________
  81 +
  82 +
  83 +### Predis is a pure-PHP implementation: it can not be fast enough! ###
  84 +
  85 +It really depends, but most of the times the answer is: _yes, it is fast enough_. I will give you a
  86 +couple of easy numbers with a simple test that uses a single client and is executed by PHP 5.5.6
  87 +against a local instance of Redis 2.8 that runs under Ubuntu 13.10 on a Intel Q6600:
  88 +
  89 +```
  90 +21000 SET/sec using 12 bytes for both key and value.
  91 +21000 GET/sec while retrieving the very same values.
  92 +0.130 seconds to fetch 30000 keys using _KEYS *_.
  93 +```
  94 +
  95 +How does it compare with [__phpredis__](http://github.com/nicolasff/phpredis), a nice C extension
  96 +providing an efficient client for Redis?
  97 +
  98 +```
  99 +30100 SET/sec using 12 bytes for both key and value
  100 +29400 GET/sec while retrieving the very same values
  101 +0.035 seconds to fetch 30000 keys using "KEYS *"".
  102 +```
  103 +
  104 +Wow __phpredis__ seems much faster! Well, we are comparing a C extension with a pure-PHP library so
  105 +lower numbers are quite expected but there is a fundamental flaw in them: is this really how you are
  106 +going to use Redis in your application? Are you really going to send thousands of commands using a
  107 +for-loop on each page request using a single client instance? If so... well I guess you are probably
  108 +doing something wrong. Also, if you need to `SET` or `GET` multiple keys you should definitely use
  109 +commands such as `MSET` and `MGET`. You can also use pipelining to get more performances when this
  110 +technique can be used.
  111 +
  112 +There is one more thing: we have tested the overhead of Predis by connecting on a localhost instance
  113 +of Redis but how these numbers change when we hit the physical network by connecting to remote Redis
  114 +instances?
  115 +
  116 +```
  117 +Using Predis:
  118 +3200 SET/sec using 12 bytes for both key and value
  119 +3200 GET/sec while retrieving the very same values
  120 +0.132 seconds to fetch 30000 keys using "KEYS *".
  121 +
  122 +Using phpredis:
  123 +3500 SET/sec using 12 bytes for both key and value
  124 +3500 GET/sec while retrieving the very same values
  125 +0.045 seconds to fetch 30000 keys using "KEYS *".
  126 +```
  127 +
  128 +There you go, you get almost the same average numbers and the reason is simple: network latency is a
  129 +real performance killer and you cannot do (almost) anything about that. As a disclaimer, remember
  130 +that we are measuring the overhead of client libraries implementations and the effects of network
  131 +round-trip times, so we are not really measuring how fast Redis is. Redis shines best with thousands
  132 +of concurrent clients doing requests! Also, actual performances should be measured according to how
  133 +your application will use Redis.
  134 +
  135 +### I am convinced, but performances for multi-bulk responses are still worse ###
  136 +
  137 +Fair enough, but there is an option available if you need even more speed and consists on installing
  138 +__[phpiredis](http://github.com/nrk/phpiredis)__ (note the additional _i_ in the name) and let the
  139 +client use it. __phpiredis__ is another C extension that wraps __hiredis__ (the official C client
  140 +library for Redis) with a thin layer exposing its features to PHP. You can then choose between two
  141 +different connection classes:
  142 +
  143 + - `Predis\Connection\PhpiredisStreamConnection` (using native PHP streams).
  144 + - `Predis\Connection\PhpiredisSocketConnection` (requires `ext-socket`).
  145 +
  146 +You will now get the benefits of a faster protocol serializer and parser just by adding a couple of
  147 +lines of code:
  148 +
  149 +```php
  150 +$client = new Predis\Client('tcp://127.0.0.1', array(
  151 + 'connections' => array(
  152 + 'tcp' => 'Predis\Connection\PhpiredisStreamConnection',
  153 + 'unix' => 'Predis\Connection\PhpiredisSocketConnection',
  154 + ),
  155 +));
  156 +```
  157 +
  158 +Dead simple. Nothing changes in the way you use the library in your application. So how fast is it
  159 +our basic benchmark script now? There are not much improvements for inline or short bulk responses
  160 +like the ones returned by `SET` and `GET`, but the speed for parsing multi-bulk responses is now on
  161 +par with phpredis:
  162 +
  163 +```
  164 +Fatching 30000 keys with _KEYS *_ using Predis paired with phpiredis::
  165 +
  166 +0.035 seconds from a local Redis instance
  167 +0.047 seconds from a remote Redis instance
  168 +```
  169 +
  170 +### If I need an extension to get better performances, why not using phpredis? ###
  171 +
  172 +Good question. Generically speaking if you need absolute uber-speed using Redis on the localhost and
  173 +you do not care about abstractions built around some Redis features such as MULTI / EXEC, or if you
  174 +do not need any kind of extensibility or guaranteed backwards compatibility with different versions
  175 +of Redis (Predis currently supports from 1.2 up to 2.8 and the current development version), then
  176 +using __phpredis__ makes absolutely sense. Otherwise, Predis is perfect for the job and by adding
  177 +__phpiredis__ you can get a nice speed bump almost for free.
  1 +Copyright (c) 2009-2016 Daniele Alessandri
  2 +
  3 +Permission is hereby granted, free of charge, to any person
  4 +obtaining a copy of this software and associated documentation
  5 +files (the "Software"), to deal in the Software without
  6 +restriction, including without limitation the rights to use,
  7 +copy, modify, merge, publish, distribute, sublicense, and/or sell
  8 +copies of the Software, and to permit persons to whom the
  9 +Software is furnished to do so, subject to the following
  10 +conditions:
  11 +
  12 +The above copyright notice and this permission notice shall be
  13 +included in all copies or substantial portions of the Software.
  14 +
  15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  17 +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18 +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  19 +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20 +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21 +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22 +OTHER DEALINGS IN THE SOFTWARE.
  1 +# Predis #
  2 +
  3 +[![Software license][ico-license]](LICENSE)
  4 +[![Latest stable][ico-version-stable]][link-packagist]
  5 +[![Latest development][ico-version-dev]][link-packagist]
  6 +[![Monthly installs][ico-downloads-monthly]][link-downloads]
  7 +[![Build status][ico-travis]][link-travis]
  8 +
  9 +Flexible and feature-complete [Redis](http://redis.io) client for PHP >= 5.3 and HHVM >= 2.3.0.
  10 +
  11 +Predis does not require any additional C extension by default, but it can be optionally paired with
  12 +[phpiredis](https://github.com/nrk/phpiredis) to lower the overhead of the serialization and parsing
  13 +of the [Redis RESP Protocol](http://redis.io/topics/protocol).
  14 +
  15 +More details about this project can be found on the [frequently asked questions](FAQ.md).
  16 +
  17 +
  18 +## Main features ##
  19 +
  20 +- Support for different versions of Redis (from __2.0__ to __3.2__) using profiles.
  21 +- Support for clustering using client-side sharding and pluggable keyspace distributors.
  22 +- Support for [redis-cluster](http://redis.io/topics/cluster-tutorial) (Redis >= 3.0).
  23 +- Support for master-slave replication setups and [redis-sentinel](http://redis.io/topics/sentinel).
  24 +- Transparent key prefixing of keys using a customizable prefix strategy.
  25 +- Command pipelining on both single nodes and clusters (client-side sharding only).
  26 +- Abstraction for Redis transactions (Redis >= 2.0) and CAS operations (Redis >= 2.2).
  27 +- Abstraction for Lua scripting (Redis >= 2.6) and automatic switching between `EVALSHA` or `EVAL`.
  28 +- Abstraction for `SCAN`, `SSCAN`, `ZSCAN` and `HSCAN` (Redis >= 2.8) based on PHP iterators.
  29 +- Connections are established lazily by the client upon the first command and can be persisted.
  30 +- Connections can be established via TCP/IP (also TLS/SSL-encrypted) or UNIX domain sockets.
  31 +- Support for [Webdis](http://webd.is) (requires both `ext-curl` and `ext-phpiredis`).
  32 +- Support for custom connection classes for providing different network or protocol backends.
  33 +- Flexible system for defining custom commands and profiles and override the default ones.
  34 +
  35 +
  36 +## How to _install_ and use Predis ##
  37 +
  38 +This library can be found on [Packagist](http://packagist.org/packages/predis/predis) for an easier
  39 +management of projects dependencies using [Composer](http://packagist.org/about-composer) or on our
  40 +[own PEAR channel](http://pear.nrk.io) for a more traditional installation using PEAR. Ultimately,
  41 +compressed archives of each release are [available on GitHub](https://github.com/predis/predis/releases).
  42 +
  43 +
  44 +### Loading the library ###
  45 +
  46 +Predis relies on the autoloading features of PHP to load its files when needed and complies with the
  47 +[PSR-4 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md).
  48 +Autoloading is handled automatically when dependencies are managed through Composer, but it is also
  49 +possible to leverage its own autoloader in projects or scripts lacking any autoload facility:
  50 +
  51 +```php
  52 +// Prepend a base path if Predis is not available in your "include_path".
  53 +require 'Predis/Autoloader.php';
  54 +
  55 +Predis\Autoloader::register();
  56 +```
  57 +
  58 +It is also possible to create a [phar](http://www.php.net/manual/en/intro.phar.php) archive directly
  59 +from the repository by launching the `bin/create-phar` script. The generated phar already contains a
  60 +stub defining its own autoloader, so you just need to `require()` it to start using the library.
  61 +
  62 +
  63 +### Connecting to Redis ###
  64 +
  65 +When creating a client instance without passing any connection parameter, Predis assumes `127.0.0.1`
  66 +and `6379` as default host and port. The default timeout for the `connect()` operation is 5 seconds:
  67 +
  68 +```php
  69 +$client = new Predis\Client();
  70 +$client->set('foo', 'bar');
  71 +$value = $client->get('foo');
  72 +```
  73 +
  74 +Connection parameters can be supplied either in the form of URI strings or named arrays. The latter
  75 +is the preferred way to supply parameters, but URI strings can be useful when parameters are read
  76 +from non-structured or partially-structured sources:
  77 +
  78 +```php
  79 +// Parameters passed using a named array:
  80 +$client = new Predis\Client([
  81 + 'scheme' => 'tcp',
  82 + 'host' => '10.0.0.1',
  83 + 'port' => 6379,
  84 +]);
  85 +
  86 +// Same set of parameters, passed using an URI string:
  87 +$client = new Predis\Client('tcp://10.0.0.1:6379');
  88 +```
  89 +
  90 +Password protected servers can be accessed by adding `password` to the parameters set. When ACLs are
  91 +enabled on Redis >= 6.0, both `username` and `password` are required for user authentication.
  92 +
  93 +It is also possible to connect to local instances of Redis using UNIX domain sockets, in this case
  94 +the parameters must use the `unix` scheme and specify a path for the socket file:
  95 +
  96 +```php
  97 +$client = new Predis\Client(['scheme' => 'unix', 'path' => '/path/to/redis.sock']);
  98 +$client = new Predis\Client('unix:/path/to/redis.sock');
  99 +```
  100 +
  101 +The client can leverage TLS/SSL encryption to connect to secured remote Redis instances without the
  102 +need to configure an SSL proxy like stunnel. This can be useful when connecting to nodes running on
  103 +various cloud hosting providers. Encryption can be enabled with using the `tls` scheme and an array
  104 +of suitable [options](http://php.net/manual/context.ssl.php) passed via the `ssl` parameter:
  105 +
  106 +```php
  107 +// Named array of connection parameters:
  108 +$client = new Predis\Client([
  109 + 'scheme' => 'tls',
  110 + 'ssl' => ['cafile' => 'private.pem', 'verify_peer' => true],
  111 +]);
  112 +
  113 +// Same set of parameters, but using an URI string:
  114 +$client = new Predis\Client('tls://127.0.0.1?ssl[cafile]=private.pem&ssl[verify_peer]=1');
  115 +```
  116 +
  117 +The connection schemes [`redis`](http://www.iana.org/assignments/uri-schemes/prov/redis) (alias of
  118 +`tcp`) and [`rediss`](http://www.iana.org/assignments/uri-schemes/prov/rediss) (alias of `tls`) are
  119 +also supported, with the difference that URI strings containing these schemes are parsed following
  120 +the rules described on their respective IANA provisional registration documents.
  121 +
  122 +The actual list of supported connection parameters can vary depending on each connection backend so
  123 +it is recommended to refer to their specific documentation or implementation for details.
  124 +
  125 +When an array of connection parameters is provided, Predis automatically works in cluster mode using
  126 +client-side sharding. Both named arrays and URI strings can be mixed when providing configurations
  127 +for each node:
  128 +
  129 +```php
  130 +$client = new Predis\Client([
  131 + 'tcp://10.0.0.1?alias=first-node',
  132 + ['host' => '10.0.0.2', 'alias' => 'second-node'],
  133 +]);
  134 +```
  135 +
  136 +See the [aggregate connections](#aggregate-connections) section of this document for more details.
  137 +
  138 +Connections to Redis are lazy meaning that the client connects to a server only if and when needed.
  139 +While it is recommended to let the client do its own stuff under the hood, there may be times when
  140 +it is still desired to have control of when the connection is opened or closed: this can easily be
  141 +achieved by invoking `$client->connect()` and `$client->disconnect()`. Please note that the effect
  142 +of these methods on aggregate connections may differ depending on each specific implementation.
  143 +
  144 +
  145 +### Client configuration ###
  146 +
  147 +Many aspects and behaviors of the client can be configured by passing specific client options to the
  148 +second argument of `Predis\Client::__construct()`:
  149 +
  150 +```php
  151 +$client = new Predis\Client($parameters, ['profile' => '2.8', 'prefix' => 'sample:']);
  152 +```
  153 +
  154 +Options are managed using a mini DI-alike container and their values can be lazily initialized only
  155 +when needed. The client options supported by default in Predis are:
  156 +
  157 + - `profile`: specifies the profile to use to match a specific version of Redis.
  158 + - `prefix`: prefix string automatically applied to keys found in commands.
  159 + - `exceptions`: whether the client should throw or return responses upon Redis errors.
  160 + - `connections`: list of connection backends or a connection factory instance.
  161 + - `cluster`: specifies a cluster backend (`predis`, `redis` or callable object).
  162 + - `replication`: specifies a replication backend (`TRUE`, `sentinel` or callable object).
  163 + - `aggregate`: overrides `cluster` and `replication` to provide a custom connections aggregator.
  164 + - `parameters`: list of default connection parameters for aggregate connections.
  165 +
  166 +Users can also provide custom options with values or callable objects (for lazy initialization) that
  167 +are stored in the options container for later use through the library.
  168 +
  169 +
  170 +### Aggregate connections ###
  171 +
  172 +Aggregate connections are the foundation upon which Predis implements clustering and replication and
  173 +they are used to group multiple connections to single Redis nodes and hide the specific logic needed
  174 +to handle them properly depending on the context. Aggregate connections usually require an array of
  175 +connection parameters when creating a new client instance.
  176 +
  177 +#### Cluster ####
  178 +
  179 +By default, when no specific client options are set and an array of connection parameters is passed
  180 +to the client's constructor, Predis configures itself to work in clustering mode using a traditional
  181 +client-side sharding approach to create a cluster of independent nodes and distribute the keyspace
  182 +among them. This approach needs some form of external health monitoring of nodes and requires manual
  183 +operations to rebalance the keyspace when changing its configuration by adding or removing nodes:
  184 +
  185 +```php
  186 +$parameters = ['tcp://10.0.0.1', 'tcp://10.0.0.2', 'tcp://10.0.0.3'];
  187 +
  188 +$client = new Predis\Client($parameters);
  189 +```
  190 +
  191 +Along with Redis 3.0, a new supervised and coordinated type of clustering was introduced in the form
  192 +of [redis-cluster](http://redis.io/topics/cluster-tutorial). This kind of approach uses a different
  193 +algorithm to distribute the keyspaces, with Redis nodes coordinating themselves by communicating via
  194 +a gossip protocol to handle health status, rebalancing, nodes discovery and request redirection. In
  195 +order to connect to a cluster managed by redis-cluster, the client requires a list of its nodes (not
  196 +necessarily complete since it will automatically discover new nodes if necessary) and the `cluster`
  197 +client options set to `redis`:
  198 +
  199 +```php
  200 +$parameters = ['tcp://10.0.0.1', 'tcp://10.0.0.2', 'tcp://10.0.0.3'];
  201 +$options = ['cluster' => 'redis'];
  202 +
  203 +$client = new Predis\Client($parameters, $options);
  204 +```
  205 +
  206 +#### Replication ####
  207 +
  208 +The client can be configured to operate in a single master / multiple slaves setup to provide better
  209 +service availability. When using replication, Predis recognizes read-only commands and sends them to
  210 +a random slave in order to provide some sort of load-balancing and switches to the master as soon as
  211 +it detects a command that performs any kind of operation that would end up modifying the keyspace or
  212 +the value of a key. Instead of raising a connection error when a slave fails, the client attempts to
  213 +fall back to a different slave among the ones provided in the configuration.
  214 +
  215 +The basic configuration needed to use the client in replication mode requires one Redis server to be
  216 +identified as the master (this can be done via connection parameters using the `alias` parameter set
  217 +to `master`) and one or more servers acting as slaves:
  218 +
  219 +```php
  220 +$parameters = ['tcp://10.0.0.1?alias=master', 'tcp://10.0.0.2', 'tcp://10.0.0.3'];
  221 +$options = ['replication' => true];
  222 +
  223 +$client = new Predis\Client($parameters, $options);
  224 +```
  225 +
  226 +The above configuration has a static list of servers and relies entirely on the client's logic, but
  227 +it is possible to rely on [`redis-sentinel`](http://redis.io/topics/sentinel) for a more robust HA
  228 +environment with sentinel servers acting as a source of authority for clients for service discovery.
  229 +The minimum configuration required by the client to work with redis-sentinel is a list of connection
  230 +parameters pointing to a bunch of sentinel instances, the `replication` option set to `sentinel` and
  231 +the `service` option set to the name of the service:
  232 +
  233 +```php
  234 +$sentinels = ['tcp://10.0.0.1', 'tcp://10.0.0.2', 'tcp://10.0.0.3'];
  235 +$options = ['replication' => 'sentinel', 'service' => 'mymaster'];
  236 +
  237 +$client = new Predis\Client($sentinels, $options);
  238 +```
  239 +
  240 +If the master and slave nodes are configured to require an authentication from clients, a password
  241 +must be provided via the global `parameters` client option. This option can also be used to specify
  242 +a different database index. The client options array would then look like this:
  243 +
  244 +```php
  245 +$options = [
  246 + 'replication' => 'sentinel',
  247 + 'service' => 'mymaster',
  248 + 'parameters' => [
  249 + 'password' => $secretpassword,
  250 + 'database' => 10,
  251 + ],
  252 +];
  253 +```
  254 +
  255 +While Predis is able to distinguish commands performing write and read-only operations, `EVAL` and
  256 +`EVALSHA` represent a corner case in which the client switches to the master node because it cannot
  257 +tell when a Lua script is safe to be executed on slaves. While this is indeed the default behavior,
  258 +when certain Lua scripts do not perform write operations it is possible to provide an hint to tell
  259 +the client to stick with slaves for their execution:
  260 +
  261 +```php
  262 +$parameters = ['tcp://10.0.0.1?alias=master', 'tcp://10.0.0.2', 'tcp://10.0.0.3'];
  263 +$options = ['replication' => function () {
  264 + // Set scripts that won't trigger a switch from a slave to the master node.
  265 + $strategy = new Predis\Replication\ReplicationStrategy();
  266 + $strategy->setScriptReadOnly($LUA_SCRIPT);
  267 +
  268 + return new Predis\Connection\Aggregate\MasterSlaveReplication($strategy);
  269 +}];
  270 +
  271 +$client = new Predis\Client($parameters, $options);
  272 +$client->eval($LUA_SCRIPT, 0); // Sticks to slave using `eval`...
  273 +$client->evalsha(sha1($LUA_SCRIPT), 0); // ... and `evalsha`, too.
  274 +```
  275 +
  276 +The [`examples`](examples/) directory contains a few scripts that demonstrate how the client can be
  277 +configured and used to leverage replication in both basic and complex scenarios.
  278 +
  279 +
  280 +### Command pipelines ###
  281 +
  282 +Pipelining can help with performances when many commands need to be sent to a server by reducing the
  283 +latency introduced by network round-trip timings. Pipelining also works with aggregate connections.
  284 +The client can execute the pipeline inside a callable block or return a pipeline instance with the
  285 +ability to chain commands thanks to its fluent interface:
  286 +
  287 +```php
  288 +// Executes a pipeline inside the given callable block:
  289 +$responses = $client->pipeline(function ($pipe) {
  290 + for ($i = 0; $i < 1000; $i++) {
  291 + $pipe->set("key:$i", str_pad($i, 4, '0', 0));
  292 + $pipe->get("key:$i");
  293 + }
  294 +});
  295 +
  296 +// Returns a pipeline that can be chained thanks to its fluent interface:
  297 +$responses = $client->pipeline()->set('foo', 'bar')->get('foo')->execute();
  298 +```
  299 +
  300 +
  301 +### Transactions ###
  302 +
  303 +The client provides an abstraction for Redis transactions based on `MULTI` and `EXEC` with a similar
  304 +interface to command pipelines:
  305 +
  306 +```php
  307 +// Executes a transaction inside the given callable block:
  308 +$responses = $client->transaction(function ($tx) {
  309 + $tx->set('foo', 'bar');
  310 + $tx->get('foo');
  311 +});
  312 +
  313 +// Returns a transaction that can be chained thanks to its fluent interface:
  314 +$responses = $client->transaction()->set('foo', 'bar')->get('foo')->execute();
  315 +```
  316 +
  317 +This abstraction can perform check-and-set operations thanks to `WATCH` and `UNWATCH` and provides
  318 +automatic retries of transactions aborted by Redis when `WATCH`ed keys are touched. For an example
  319 +of a transaction using CAS you can see [the following example](examples/transaction_using_cas.php).
  320 +
  321 +
  322 +### Adding new commands ###
  323 +
  324 +While we try to update Predis to stay up to date with all the commands available in Redis, you might
  325 +prefer to stick with an old version of the library or provide a different way to filter arguments or
  326 +parse responses for specific commands. To achieve that, Predis provides the ability to implement new
  327 +command classes to define or override commands in the default server profiles used by the client:
  328 +
  329 +```php
  330 +// Define a new command by extending Predis\Command\Command:
  331 +class BrandNewRedisCommand extends Predis\Command\Command
  332 +{
  333 + public function getId()
  334 + {
  335 + return 'NEWCMD';
  336 + }
  337 +}
  338 +
  339 +// Inject your command in the current profile:
  340 +$client = new Predis\Client();
  341 +$client->getProfile()->defineCommand('newcmd', 'BrandNewRedisCommand');
  342 +
  343 +$response = $client->newcmd();
  344 +```
  345 +
  346 +There is also a method to send raw commands without filtering their arguments or parsing responses.
  347 +Users must provide the list of arguments for the command as an array, following the signatures as
  348 +defined by the [Redis documentation for commands](http://redis.io/commands):
  349 +
  350 +```php
  351 +$response = $client->executeRaw(['SET', 'foo', 'bar']);
  352 +```
  353 +
  354 +
  355 +### Script commands ###
  356 +
  357 +While it is possible to leverage [Lua scripting](http://redis.io/commands/eval) on Redis 2.6+ using
  358 +directly [`EVAL`](http://redis.io/commands/eval) and [`EVALSHA`](http://redis.io/commands/evalsha),
  359 +Predis offers script commands as an higher level abstraction built upon them to make things simple.
  360 +Script commands can be registered in the server profile used by the client and are accessible as if
  361 +they were plain Redis commands, but they define Lua scripts that get transmitted to the server for
  362 +remote execution. Internally they use [`EVALSHA`](http://redis.io/commands/evalsha) by default and
  363 +identify a script by its SHA1 hash to save bandwidth, but [`EVAL`](http://redis.io/commands/eval)
  364 +is used as a fall back when needed:
  365 +
  366 +```php
  367 +// Define a new script command by extending Predis\Command\ScriptCommand:
  368 +class ListPushRandomValue extends Predis\Command\ScriptCommand
  369 +{
  370 + public function getKeysCount()
  371 + {
  372 + return 1;
  373 + }
  374 +
  375 + public function getScript()
  376 + {
  377 + return <<<LUA
  378 +math.randomseed(ARGV[1])
  379 +local rnd = tostring(math.random())
  380 +redis.call('lpush', KEYS[1], rnd)
  381 +return rnd
  382 +LUA;
  383 + }
  384 +}
  385 +
  386 +// Inject the script command in the current profile:
  387 +$client = new Predis\Client();
  388 +$client->getProfile()->defineCommand('lpushrand', 'ListPushRandomValue');
  389 +
  390 +$response = $client->lpushrand('random_values', $seed = mt_rand());
  391 +```
  392 +
  393 +
  394 +### Customizable connection backends ###
  395 +
  396 +Predis can use different connection backends to connect to Redis. Two of them leverage a third party
  397 +extension such as [phpiredis](https://github.com/nrk/phpiredis) resulting in major performance gains
  398 +especially when dealing with big multibulk responses. While one is based on PHP streams, the other
  399 +is based on socket resources provided by `ext-socket`. Both support TCP/IP and UNIX domain sockets:
  400 +
  401 +```php
  402 +$client = new Predis\Client('tcp://127.0.0.1', [
  403 + 'connections' => [
  404 + 'tcp' => 'Predis\Connection\PhpiredisStreamConnection', // PHP stream resources
  405 + 'unix' => 'Predis\Connection\PhpiredisSocketConnection', // ext-socket resources
  406 + ],
  407 +]);
  408 +```
  409 +
  410 +Developers can create their own connection classes to support whole new network backends, extend
  411 +existing classes or provide completely different implementations. Connection classes must implement
  412 +`Predis\Connection\NodeConnectionInterface` or extend `Predis\Connection\AbstractConnection`:
  413 +
  414 +```php
  415 +class MyConnectionClass implements Predis\Connection\NodeConnectionInterface
  416 +{
  417 + // Implementation goes here...
  418 +}
  419 +
  420 +// Use MyConnectionClass to handle connections for the `tcp` scheme:
  421 +$client = new Predis\Client('tcp://127.0.0.1', [
  422 + 'connections' => ['tcp' => 'MyConnectionClass'],
  423 +]);
  424 +```
  425 +
  426 +For a more in-depth insight on how to create new connection backends you can refer to the actual
  427 +implementation of the standard connection classes available in the `Predis\Connection` namespace.
  428 +
  429 +
  430 +## Development ##
  431 +
  432 +
  433 +### Reporting bugs and contributing code ###
  434 +
  435 +Contributions to Predis are highly appreciated either in the form of pull requests for new features,
  436 +bug fixes, or just bug reports. We only ask you to adhere to a [basic set of rules](CONTRIBUTING.md)
  437 +before submitting your changes or filing bugs on the issue tracker to make it easier for everyone to
  438 +stay consistent while working on the project.
  439 +
  440 +
  441 +### Test suite ###
  442 +
  443 +__ATTENTION__: Do not ever run the test suite shipped with Predis against instances of Redis running
  444 +in production environments or containing data you are interested in!
  445 +
  446 +Predis has a comprehensive test suite covering every aspect of the library. This test suite performs
  447 +integration tests against a running instance of Redis (>= 2.4.0 is required) to verify the correct
  448 +behavior of the implementation of each command and automatically skips commands not defined in the
  449 +specified Redis profile. If you do not have Redis up and running, integration tests can be disabled.
  450 +By default the test suite is configured to execute integration tests using the profile for Redis 3.2
  451 +(which is the current stable version of Redis) but can optionally target a Redis instance built from
  452 +the `unstable` branch by modifying `phpunit.xml` and setting `REDIS_SERVER_VERSION` to `dev` so that
  453 +the development server profile will be used. You can refer to [the tests README](tests/README.md)
  454 +for more detailed information about testing Predis.
  455 +
  456 +Predis uses Travis CI for continuous integration and the history for past and current builds can be
  457 +found [on its project page](http://travis-ci.org/predis/predis).
  458 +
  459 +
  460 +## Other ##
  461 +
  462 +
  463 +### Project related links ###
  464 +
  465 +- [Source code](https://github.com/predis/predis)
  466 +- [Wiki](https://github.com/predis/predis/wiki)
  467 +- [Issue tracker](https://github.com/predis/predis/issues)
  468 +- [PEAR channel](http://pear.nrk.io)
  469 +
  470 +
  471 +### Author ###
  472 +
  473 +- [Daniele Alessandri](mailto:suppakilla@gmail.com) ([twitter](http://twitter.com/JoL1hAHN))
  474 +
  475 +
  476 +### License ###
  477 +
  478 +The code for Predis is distributed under the terms of the MIT license (see [LICENSE](LICENSE)).
  479 +
  480 +[ico-license]: https://img.shields.io/github/license/predis/predis.svg?style=flat-square
  481 +[ico-version-stable]: https://img.shields.io/packagist/v/predis/predis.svg?style=flat-square
  482 +[ico-version-dev]: https://img.shields.io/packagist/vpre/predis/predis.svg?style=flat-square
  483 +[ico-downloads-monthly]: https://img.shields.io/packagist/dm/predis/predis.svg?style=flat-square
  484 +[ico-travis]: https://img.shields.io/travis/predis/predis.svg?style=flat-square
  485 +[ico-hhvm]: https://img.shields.io/hhvm/predis/predis.svg?style=flat-square
  486 +
  487 +[link-packagist]: https://packagist.org/packages/predis/predis
  488 +[link-travis]: https://travis-ci.org/predis/predis
  489 +[link-downloads]: https://packagist.org/packages/predis/predis/stats
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/src/Autoloader.php';
  13 +
  14 +Predis\Autoloader::register();
  1 +#!/usr/bin/env php
  2 +<?php
  3 +
  4 +/*
  5 + * This file is part of the Predis package.
  6 + *
  7 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  8 + *
  9 + * For the full copyright and license information, please view the LICENSE
  10 + * file that was distributed with this source code.
  11 + */
  12 +
  13 +// -------------------------------------------------------------------------- //
  14 +// This script can be used to automatically generate a file with the scheleton
  15 +// of a test case to test a Redis command by specifying the name of the class
  16 +// in the Predis\Command namespace (only classes in this namespace are valid).
  17 +// For example, to generate a test case for SET (which is represented by the
  18 +// Predis\Command\StringSet class):
  19 +//
  20 +// $ ./bin/generate-command-test --class=StringSet
  21 +//
  22 +// Here is a list of optional arguments:
  23 +//
  24 +// --realm: each command has its own realm (commands that operate on strings,
  25 +// lists, sets and such) but while this realm is usually inferred from the name
  26 +// of the specified class, sometimes it can be useful to override it with a
  27 +// custom one.
  28 +//
  29 +// --output: write the generated test case to the specified path instead of
  30 +// the default one.
  31 +//
  32 +// --overwrite: pre-existing test files are not overwritten unless this option
  33 +// is explicitly specified.
  34 +// -------------------------------------------------------------------------- //
  35 +
  36 +use Predis\Command\CommandInterface;
  37 +use Predis\Command\PrefixableCommandInterface;
  38 +
  39 +class CommandTestCaseGenerator
  40 +{
  41 + private $options;
  42 +
  43 + public function __construct(array $options)
  44 + {
  45 + if (!isset($options['class'])) {
  46 + throw new RuntimeException("Missing 'class' option.");
  47 + }
  48 + $this->options = $options;
  49 + }
  50 +
  51 + public static function fromCommandLine()
  52 + {
  53 + $parameters = array(
  54 + 'c:' => 'class:',
  55 + 'r::' => 'realm::',
  56 + 'o::' => 'output::',
  57 + 'x::' => 'overwrite::'
  58 + );
  59 +
  60 + $getops = getopt(implode(array_keys($parameters)), $parameters);
  61 +
  62 + $options = array(
  63 + 'overwrite' => false,
  64 + 'tests' => __DIR__.'/../tests/Predis',
  65 + );
  66 +
  67 + foreach ($getops as $option => $value) {
  68 + switch ($option) {
  69 + case 'c':
  70 + case 'class':
  71 + $options['class'] = $value;
  72 + break;
  73 +
  74 + case 'r':
  75 + case 'realm':
  76 + $options['realm'] = $value;
  77 + break;
  78 +
  79 + case 'o':
  80 + case 'output':
  81 + $options['output'] = $value;
  82 + break;
  83 +
  84 + case 'x':
  85 + case 'overwrite':
  86 + $options['overwrite'] = true;
  87 + break;
  88 + }
  89 + }
  90 +
  91 + if (!isset($options['class'])) {
  92 + throw new RuntimeException("Missing 'class' option.");
  93 + }
  94 +
  95 + $options['fqn'] = "Predis\\Command\\{$options['class']}";
  96 + $options['path'] = "Command/{$options['class']}.php";
  97 +
  98 + $source = __DIR__.'/../src/'.$options['path'];
  99 + if (!file_exists($source)) {
  100 + throw new RuntimeException("Cannot find class file for {$options['fqn']} in $source.");
  101 + }
  102 +
  103 + if (!isset($options['output'])) {
  104 + $options['output'] = sprintf("%s/%s", $options['tests'], str_replace('.php', 'Test.php', $options['path']));
  105 + }
  106 +
  107 + return new self($options);
  108 + }
  109 +
  110 + protected function getTestRealm()
  111 + {
  112 + if (isset($this->options['realm'])) {
  113 + if (!$this->options['realm']) {
  114 + throw new RuntimeException('Invalid value for realm has been sepcified (empty).');
  115 + }
  116 + return $this->options['realm'];
  117 + }
  118 +
  119 + $fqnParts = explode('\\', $this->options['fqn']);
  120 + $class = array_pop($fqnParts);
  121 + list($realm,) = preg_split('/([[:upper:]][[:lower:]]+)/', $class, 2, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  122 +
  123 + return strtolower($realm);
  124 + }
  125 +
  126 + public function generate()
  127 + {
  128 + $reflection = new ReflectionClass($class = $this->options['fqn']);
  129 +
  130 + if (!$reflection->isInstantiable()) {
  131 + throw new RuntimeException("Class $class must be instantiable, abstract classes or interfaces are not allowed.");
  132 + }
  133 + if (!$reflection->implementsInterface('Predis\Command\CommandInterface')) {
  134 + throw new RuntimeException("Class $class must implement Predis\Command\CommandInterface.");
  135 + }
  136 +
  137 + /*
  138 + * @var CommandInterface
  139 + */
  140 + $instance = $reflection->newInstance();
  141 +
  142 + $buffer = $this->getTestCaseBuffer($instance);
  143 +
  144 + return $buffer;
  145 + }
  146 +
  147 + public function save()
  148 + {
  149 + $options = $this->options;
  150 + if (file_exists($options['output']) && !$options['overwrite']) {
  151 + throw new RuntimeException("File {$options['output']} already exist. Specify the --overwrite option to overwrite the existing file.");
  152 + }
  153 + file_put_contents($options['output'], $this->generate());
  154 + }
  155 +
  156 + protected function getTestCaseBuffer(CommandInterface $instance)
  157 + {
  158 + $id = $instance->getId();
  159 + $fqn = get_class($instance);
  160 + $fqnParts = explode('\\', $fqn);
  161 + $class = array_pop($fqnParts) . "Test";
  162 + $realm = $this->getTestRealm();
  163 +
  164 + $buffer =<<<PHP
  165 +<?php
  166 +
  167 +/*
  168 + * This file is part of the Predis package.
  169 + *
  170 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  171 + *
  172 + * For the full copyright and license information, please view the LICENSE
  173 + * file that was distributed with this source code.
  174 + */
  175 +
  176 +namespace Predis\Command;
  177 +
  178 +/**
  179 + * @group commands
  180 + * @group realm-$realm
  181 + */
  182 +class $class extends PredisCommandTestCase
  183 +{
  184 + /**
  185 + * {@inheritdoc}
  186 + */
  187 + protected function getExpectedCommand()
  188 + {
  189 + return '$fqn';
  190 + }
  191 +
  192 + /**
  193 + * {@inheritdoc}
  194 + */
  195 + protected function getExpectedId()
  196 + {
  197 + return '$id';
  198 + }
  199 +
  200 + /**
  201 + * @group disconnected
  202 + */
  203 + public function testFilterArguments()
  204 + {
  205 + \$this->markTestIncomplete('This test has not been implemented yet.');
  206 +
  207 + \$arguments = array(/* add arguments */);
  208 + \$expected = array(/* add arguments */);
  209 +
  210 + \$command = \$this->getCommand();
  211 + \$command->setArguments(\$arguments);
  212 +
  213 + \$this->assertSame(\$expected, \$command->getArguments());
  214 + }
  215 +
  216 + /**
  217 + * @group disconnected
  218 + */
  219 + public function testParseResponse()
  220 + {
  221 + \$this->markTestIncomplete('This test has not been implemented yet.');
  222 +
  223 + \$raw = null;
  224 + \$expected = null;
  225 +
  226 + \$command = \$this->getCommand();
  227 +
  228 + \$this->assertSame(\$expected, \$command->parseResponse(\$raw));
  229 + }
  230 +
  231 +PHP;
  232 +
  233 + if ($instance instanceof PrefixableCommandInterface) {
  234 + $buffer .=<<<PHP
  235 +
  236 + /**
  237 + * @group disconnected
  238 + */
  239 + public function testPrefixKeys()
  240 + {
  241 + \$this->markTestIncomplete('This test has not been implemented yet.');
  242 +
  243 + \$arguments = array(/* add arguments */);
  244 + \$expected = array(/* add arguments */);
  245 +
  246 + \$command = \$this->getCommandWithArgumentsArray(\$arguments);
  247 + \$command->prefixKeys('prefix:');
  248 +
  249 + \$this->assertSame(\$expected, \$command->getArguments());
  250 + }
  251 +
  252 + /**
  253 + * @group disconnected
  254 + */
  255 + public function testPrefixKeysIgnoredOnEmptyArguments()
  256 + {
  257 + \$command = \$this->getCommand();
  258 + \$command->prefixKeys('prefix:');
  259 +
  260 + \$this->assertSame(array(), \$command->getArguments());
  261 + }
  262 +
  263 +PHP;
  264 + }
  265 +
  266 + return "$buffer}\n";
  267 + }
  268 +}
  269 +
  270 +// ------------------------------------------------------------------------- //
  271 +
  272 +require __DIR__.'/../autoload.php';
  273 +
  274 +$generator = CommandTestCaseGenerator::fromCommandLine();
  275 +$generator->save();
  1 +#!/usr/bin/env php
  2 +<?php
  3 +
  4 +/*
  5 + * This file is part of the Predis package.
  6 + *
  7 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  8 + *
  9 + * For the full copyright and license information, please view the LICENSE
  10 + * file that was distributed with this source code.
  11 + */
  12 +
  13 +// -------------------------------------------------------------------------- //
  14 +// In order to be able to execute this script to create a PEAR package of Predis
  15 +// the `pear` binary must be available and executable in your $PATH.
  16 +// The parts used to parse author and version strings are taken from Onion (used
  17 +// by this library in the past) just to keep on relying on the package.ini file
  18 +// to simplify things. We might consider to switch to using the PEAR classes
  19 +// directly in the future.
  20 +// -------------------------------------------------------------------------- //
  21 +
  22 +function executeWithBackup($file, $callback)
  23 +{
  24 + $exception = null;
  25 + $backup = "$file.backup";
  26 +
  27 + copy($file, $backup);
  28 +
  29 + try {
  30 + call_user_func($callback, $file);
  31 + } catch (Exception $exception) {
  32 + // NOOP
  33 + }
  34 +
  35 + unlink($file);
  36 + rename($backup, $file);
  37 +
  38 + if ($exception) {
  39 + throw $exception;
  40 + }
  41 +}
  42 +
  43 +function parseAuthor($string)
  44 +{
  45 + $author = array();
  46 +
  47 + if (preg_match('/^\s*(.+?)\s*(?:"(\S+)"\s*)?<(\S+)>\s*$/x', $string , $regs)) {
  48 + if (count($regs) == 4) {
  49 + list($_,$name,$user,$email) = $regs;
  50 + $author['name'] = $name;
  51 + $author['user'] = $user;
  52 + $author['email'] = $email;
  53 + } elseif (count($regs) == 3) {
  54 + list($_,$name,$email) = $regs;
  55 + $author['name'] = $name;
  56 + $author['email'] = $email;
  57 + }
  58 + } else {
  59 + $author['name'] = $string;
  60 + }
  61 +
  62 + return $author;
  63 +}
  64 +
  65 +function parseVersion($string)
  66 +{
  67 + $version_pattern = '([0-9.]+)';
  68 +
  69 + if (preg_match("/^\s*$version_pattern\s*\$/x", $string, $regs)) {
  70 + return array('min' => $regs[1] ?: '0.0.0');
  71 + } elseif (preg_match("/^\s*[>=]+\s*$version_pattern\s*\$/x", $string, $regs)) {
  72 + return array('min' => $regs[1] ?: '0.0.0');
  73 + } elseif (preg_match("/^\s*[<=]+\s*$version_pattern\s*\$/x", $string, $regs)) {
  74 + return array('max' => $regs[1]);
  75 + } elseif (preg_match("/^\s*$version_pattern\s*<=>\s*$version_pattern\s*\$/x", $string, $regs)) {
  76 + return array(
  77 + 'min' => $regs[1] ?: '0.0.0',
  78 + 'max' => $regs[2],
  79 + );
  80 + }
  81 +
  82 + return null;
  83 +}
  84 +
  85 +function addRolePath($pkg, $path, $role)
  86 +{
  87 + if (is_dir($path)) {
  88 + $dirRoot = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
  89 + $dirTree = new RecursiveIteratorIterator($dirRoot, RecursiveIteratorIterator::CHILD_FIRST);
  90 +
  91 + foreach ($dirTree as $fileinfo) {
  92 + if ($fileinfo->isFile()) {
  93 + addPackageFile($pkg, $fileinfo, $role, $path);
  94 + }
  95 + }
  96 + } else {
  97 + foreach (glob($path) as $filename) {
  98 + addPackageFile($pkg, new SplFileInfo($filename), $role);
  99 + }
  100 + }
  101 +}
  102 +
  103 +function addPackageFile($pkg, $fileinfo, $role, $baseDir = '')
  104 +{
  105 + $fileNode = $pkg->contents->dir->addChild('file');
  106 + $fileNode->addAttribute('name', $filepath = $fileinfo->getPathname());
  107 + $fileNode->addAttribute('role', $role);
  108 + $fileNode->addAttribute('md5sum', md5_file($filepath));
  109 +
  110 + $installNode = $pkg->phprelease->filelist->addChild('install');
  111 + $installNode->addAttribute('name', $filepath);
  112 + $installNode->addAttribute('as', !$baseDir ? basename($filepath) : substr($filepath, strlen($baseDir) + 1));
  113 +}
  114 +
  115 +function generatePackageXml($packageINI)
  116 +{
  117 + $XML = <<<XML
  118 +<?xml version="1.0" encoding="UTF-8"?>
  119 +<package packagerversion="1.4.10" version="2.0"
  120 + xmlns="http://pear.php.net/dtd/package-2.0"
  121 + xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
  122 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  123 + xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
  124 + http://pear.php.net/dtd/tasks-1.0.xsd
  125 + http://pear.php.net/dtd/package-2.0
  126 + http://pear.php.net/dtd/package-2.0.xsd" />
  127 +XML;
  128 +
  129 + $cfg = parse_ini_file($packageINI, true);
  130 + $pkg = new SimpleXMLElement($XML);
  131 +
  132 + $pkg->name = $cfg['package']['name'];
  133 + $pkg->channel = $cfg['package']['channel'];
  134 + $pkg->summary = $cfg['package']['desc'];
  135 + $pkg->description = $cfg['package']['desc'];
  136 +
  137 + $author = parseAuthor($cfg['package']['author']);
  138 + $pkg->addChild('lead');
  139 + $pkg->lead->name = $author['name'];
  140 + $pkg->lead->user = $author['user'];
  141 + $pkg->lead->email = $author['email'];
  142 + $pkg->lead->active = 'yes';
  143 +
  144 + $datetime = new DateTime('now');
  145 + $pkg->date = $datetime->format('Y-m-d');
  146 + $pkg->time = $datetime->format('H:i:s');
  147 +
  148 + $pkg->addChild('version');
  149 + $pkg->version->release = $cfg['package']['version'];
  150 + $pkg->version->api = $cfg['package']['version'];
  151 +
  152 + $pkg->addChild('stability');
  153 + $pkg->stability->release = $cfg['package']['stability'];
  154 + $pkg->stability->api = $cfg['package']['stability'];
  155 +
  156 + $pkg->license = $cfg['package']['license'];
  157 + $pkg->notes = '-';
  158 +
  159 + $pkg->addChild('contents')->addChild('dir')->addAttribute('name', '/');
  160 +
  161 + $pkg->addChild('dependencies')->addChild('required');
  162 + foreach ($cfg['require'] as $required => $version) {
  163 + $version = parseVersion($version);
  164 + $pkg->dependencies->required->addChild($required);
  165 +
  166 + if (isset($version['min'])) {
  167 + $pkg->dependencies->required->$required->min = $version['min'];
  168 + }
  169 + if (isset($version['max'])) {
  170 + $pkg->dependencies->required->$required->min = $version['max'];
  171 + }
  172 + }
  173 +
  174 + $pkg->addChild('phprelease')->addChild('filelist');
  175 +
  176 + $pathToRole = array(
  177 + 'doc' => 'doc', 'docs' => 'doc', 'examples' => 'doc',
  178 + 'lib' => 'php', 'src' => 'php',
  179 + 'test' => 'test', 'tests' => 'test',
  180 + );
  181 +
  182 + foreach (array_merge($pathToRole, $cfg['roles'] ?: array()) as $path => $role) {
  183 + addRolePath($pkg, $path, $role);
  184 + }
  185 +
  186 + return $pkg;
  187 +}
  188 +
  189 +function rewritePackageInstallAs($pkg)
  190 +{
  191 + foreach ($pkg->phprelease->filelist->install as $file) {
  192 + if (preg_match('/^src\//', $file['name'])) {
  193 + $file['as'] = "Predis/{$file['as']}";
  194 + }
  195 + }
  196 +}
  197 +
  198 +function savePackageXml($xml)
  199 +{
  200 + $dom = new DOMDocument("1.0", "UTF-8");
  201 + $dom->preserveWhiteSpace = false;
  202 + $dom->formatOutput = true;
  203 + $dom->loadXML($xml->asXML());
  204 +
  205 + file_put_contents('package.xml', $dom->saveXML());
  206 +}
  207 +
  208 +function buildPackage()
  209 +{
  210 + passthru('pear -q package && rm package.xml');
  211 +}
  212 +
  213 +function modifyPhpunitXml($file)
  214 +{
  215 + $cfg = new SimpleXMLElement($file, null, true);
  216 +
  217 + $cfg[0]['bootstrap'] = str_replace('tests/', '', $cfg[0]['bootstrap']);
  218 + $cfg->testsuites->testsuite->directory = str_replace('tests/', '', $cfg->testsuites->testsuite->directory);
  219 +
  220 + $cfg->saveXml($file);
  221 +}
  222 +
  223 +// -------------------------------------------------------------------------- //
  224 +
  225 +executeWithBackup(__DIR__.'/../phpunit.xml.dist', function ($file) {
  226 + modifyPhpunitXml($file);
  227 +
  228 + $pkg = generatePackageXml('package.ini');
  229 + rewritePackageInstallAs($pkg);
  230 + savePackageXml($pkg);
  231 +
  232 + buildPackage();
  233 +});
  1 +#!/usr/bin/env php
  2 +<?php
  3 +
  4 +/*
  5 + * This file is part of the Predis package.
  6 + *
  7 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  8 + *
  9 + * For the full copyright and license information, please view the LICENSE
  10 + * file that was distributed with this source code.
  11 + */
  12 +
  13 +// -------------------------------------------------------------------------- //
  14 +// In order to be able to execute this script to create a Phar archive of Predis,
  15 +// the Phar module must be loaded and the "phar.readonly" directive php.ini must
  16 +// be set to "off". You can change the values in the $options array to customize
  17 +// the creation of the Phar archive to better suit your needs.
  18 +// -------------------------------------------------------------------------- //
  19 +
  20 +$options = array(
  21 + 'name' => 'predis',
  22 + 'project_path' => __DIR__ . '/../src',
  23 + 'compression' => Phar::NONE,
  24 + 'append_version' => true,
  25 +);
  26 +
  27 +function getPharFilename($options)
  28 +{
  29 + $filename = $options['name'];
  30 +
  31 + // NOTE: do not consider "append_version" with Phar compression do to a bug in
  32 + // Phar::compress() when renaming phar archives containing dots in their name.
  33 + if ($options['append_version'] && $options['compression'] === Phar::NONE) {
  34 + $versionFile = @fopen(__DIR__ . '/../VERSION', 'r');
  35 +
  36 + if ($versionFile === false) {
  37 + throw new Exception("Could not locate the VERSION file.");
  38 + }
  39 +
  40 + $version = trim(fgets($versionFile));
  41 + fclose($versionFile);
  42 + $filename .= "_$version";
  43 + }
  44 +
  45 + return "$filename.phar";
  46 +}
  47 +
  48 +function getPharStub($options)
  49 +{
  50 + return <<<EOSTUB
  51 +<?php
  52 +Phar::mapPhar('predis.phar');
  53 +spl_autoload_register(function (\$class) {
  54 + if (strpos(\$class, 'Predis\\\\') === 0) {
  55 + \$file = 'phar://predis.phar/'.strtr(substr(\$class, 7), '\\\', '/').'.php';
  56 + if (file_exists(\$file)) {
  57 + require \$file;
  58 + return true;
  59 + }
  60 + }
  61 +});
  62 +__halt_compiler();
  63 +EOSTUB;
  64 +}
  65 +
  66 +// -------------------------------------------------------------------------- //
  67 +
  68 +$phar = new Phar(getPharFilename($options));
  69 +$phar->compress($options['compression']);
  70 +$phar->setStub(getPharStub($options));
  71 +$phar->buildFromDirectory($options['project_path']);
  1 +#!/usr/bin/env php
  2 +<?php
  3 +
  4 +/*
  5 + * This file is part of the Predis package.
  6 + *
  7 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  8 + *
  9 + * For the full copyright and license information, please view the LICENSE
  10 + * file that was distributed with this source code.
  11 + */
  12 +
  13 +// -------------------------------------------------------------------------- //
  14 +// This script can be used to automatically glue all the .php files of Predis
  15 +// into a single monolithic script file that can be used without an autoloader,
  16 +// just like the other previous versions of the library.
  17 +//
  18 +// Much of its complexity is due to the fact that we cannot simply join PHP
  19 +// files, but namespaces and classes definitions must follow a precise order
  20 +// when dealing with subclassing and inheritance.
  21 +//
  22 +// The current implementation is pretty naïve, but it should do for now.
  23 +// -------------------------------------------------------------------------- //
  24 +
  25 +class CommandLine
  26 +{
  27 + public static function getOptions()
  28 + {
  29 + $parameters = array(
  30 + 's:' => 'source:',
  31 + 'o:' => 'output:',
  32 + 'e:' => 'exclude:',
  33 + 'E:' => 'exclude-classes:',
  34 + );
  35 +
  36 + $getops = getopt(implode(array_keys($parameters)), $parameters);
  37 +
  38 + $options = array(
  39 + 'source' => __DIR__ . "/../src",
  40 + 'output' => PredisFile::NS_ROOT . '.php',
  41 + 'exclude' => array(),
  42 + );
  43 +
  44 + foreach ($getops as $option => $value) {
  45 + switch ($option) {
  46 + case 's':
  47 + case 'source':
  48 + $options['source'] = $value;
  49 + break;
  50 +
  51 + case 'o':
  52 + case 'output':
  53 + $options['output'] = $value;
  54 + break;
  55 +
  56 + case 'E':
  57 + case 'exclude-classes':
  58 + $options['exclude'] = @file($value, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: $value;
  59 + break;
  60 +
  61 + case 'e':
  62 + case 'exclude':
  63 + $options['exclude'] = is_array($value) ? $value : array($value);
  64 + break;
  65 + }
  66 + }
  67 +
  68 + return $options;
  69 + }
  70 +}
  71 +
  72 +class PredisFile
  73 +{
  74 + const NS_ROOT = 'Predis';
  75 +
  76 + private $namespaces;
  77 +
  78 + public function __construct()
  79 + {
  80 + $this->namespaces = array();
  81 + }
  82 +
  83 + public static function from($libraryPath, array $exclude = array())
  84 + {
  85 + $predisFile = new PredisFile();
  86 + $libIterator = new RecursiveDirectoryIterator($libraryPath);
  87 +
  88 + foreach (new RecursiveIteratorIterator($libIterator) as $classFile)
  89 + {
  90 + if (!$classFile->isFile()) {
  91 + continue;
  92 + }
  93 +
  94 + $namespace = self::NS_ROOT.strtr(str_replace($libraryPath, '', $classFile->getPath()), '/', '\\');
  95 +
  96 + if (in_array(sprintf('%s\\%s', $namespace, $classFile->getBasename('.php')), $exclude)) {
  97 + continue;
  98 + }
  99 +
  100 + $phpNamespace = $predisFile->getNamespace($namespace);
  101 +
  102 + if ($phpNamespace === false) {
  103 + $phpNamespace = new PhpNamespace($namespace);
  104 + $predisFile->addNamespace($phpNamespace);
  105 + }
  106 +
  107 + $phpClass = new PhpClass($phpNamespace, $classFile);
  108 + }
  109 +
  110 + return $predisFile;
  111 + }
  112 +
  113 + public function addNamespace(PhpNamespace $namespace)
  114 + {
  115 + if (isset($this->namespaces[(string)$namespace])) {
  116 + throw new InvalidArgumentException("Duplicated namespace");
  117 + }
  118 + $this->namespaces[(string)$namespace] = $namespace;
  119 + }
  120 +
  121 + public function getNamespaces()
  122 + {
  123 + return $this->namespaces;
  124 + }
  125 +
  126 + public function getNamespace($namespace)
  127 + {
  128 + if (!isset($this->namespaces[$namespace])) {
  129 + return false;
  130 + }
  131 +
  132 + return $this->namespaces[$namespace];
  133 + }
  134 +
  135 + public function getClassByFQN($classFqn)
  136 + {
  137 + if (($nsLastPos = strrpos($classFqn, '\\')) !== false) {
  138 + $namespace = $this->getNamespace(substr($classFqn, 0, $nsLastPos));
  139 + if ($namespace === false) {
  140 + return null;
  141 + }
  142 + $className = substr($classFqn, $nsLastPos + 1);
  143 +
  144 + return $namespace->getClass($className);
  145 + }
  146 +
  147 + return null;
  148 + }
  149 +
  150 + private function calculateDependencyScores(&$classes, $fqn)
  151 + {
  152 + if (!isset($classes[$fqn])) {
  153 + $classes[$fqn] = 0;
  154 + }
  155 +
  156 + $classes[$fqn] += 1;
  157 +
  158 + if (($phpClass = $this->getClassByFQN($fqn)) === null) {
  159 + throw new RuntimeException(
  160 + "Cannot found the class $fqn which is required by other subclasses. Are you missing a file?"
  161 + );
  162 + }
  163 +
  164 + foreach ($phpClass->getDependencies() as $fqn) {
  165 + $this->calculateDependencyScores($classes, $fqn);
  166 + }
  167 + }
  168 +
  169 + private function getDependencyScores()
  170 + {
  171 + $classes = array();
  172 +
  173 + foreach ($this->getNamespaces() as $phpNamespace) {
  174 + foreach ($phpNamespace->getClasses() as $phpClass) {
  175 + $this->calculateDependencyScores($classes, $phpClass->getFQN());
  176 + }
  177 + }
  178 +
  179 + return $classes;
  180 + }
  181 +
  182 + private function getOrderedNamespaces($dependencyScores)
  183 + {
  184 + $namespaces = array_fill_keys(array_unique(
  185 + array_map(
  186 + function ($fqn) { return PhpNamespace::extractName($fqn); },
  187 + array_keys($dependencyScores)
  188 + )
  189 + ), 0);
  190 +
  191 + foreach ($dependencyScores as $classFqn => $score) {
  192 + $namespaces[PhpNamespace::extractName($classFqn)] += $score;
  193 + }
  194 +
  195 + arsort($namespaces);
  196 +
  197 + return array_keys($namespaces);
  198 + }
  199 +
  200 + private function getOrderedClasses(PhpNamespace $phpNamespace, $classes)
  201 + {
  202 + $nsClassesFQNs = array_map(function ($cl) { return $cl->getFQN(); }, $phpNamespace->getClasses());
  203 + $nsOrderedClasses = array();
  204 +
  205 + foreach ($nsClassesFQNs as $nsClassFQN) {
  206 + $nsOrderedClasses[$nsClassFQN] = $classes[$nsClassFQN];
  207 + }
  208 +
  209 + arsort($nsOrderedClasses);
  210 +
  211 + return array_keys($nsOrderedClasses);
  212 + }
  213 +
  214 + public function getPhpCode()
  215 + {
  216 + $buffer = array("<?php\n\n", PhpClass::LICENSE_HEADER, "\n\n");
  217 + $classes = $this->getDependencyScores();
  218 + $namespaces = $this->getOrderedNamespaces($classes);
  219 +
  220 + foreach ($namespaces as $namespace) {
  221 + $phpNamespace = $this->getNamespace($namespace);
  222 +
  223 + // generate namespace directive
  224 + $buffer[] = $phpNamespace->getPhpCode();
  225 + $buffer[] = "\n";
  226 +
  227 + // generate use directives
  228 + $useDirectives = $phpNamespace->getUseDirectives();
  229 + if (count($useDirectives) > 0) {
  230 + $buffer[] = $useDirectives->getPhpCode();
  231 + $buffer[] = "\n";
  232 + }
  233 +
  234 + // generate classes bodies
  235 + $nsClasses = $this->getOrderedClasses($phpNamespace, $classes);
  236 + foreach ($nsClasses as $classFQN) {
  237 + $buffer[] = $this->getClassByFQN($classFQN)->getPhpCode();
  238 + $buffer[] = "\n\n";
  239 + }
  240 +
  241 + $buffer[] = "/* " . str_repeat("-", 75) . " */";
  242 + $buffer[] = "\n\n";
  243 + }
  244 +
  245 + return implode($buffer);
  246 + }
  247 +
  248 + public function saveTo($outputFile)
  249 + {
  250 + // TODO: add more sanity checks
  251 + if ($outputFile === null || $outputFile === '') {
  252 + throw new InvalidArgumentException('You must specify a valid output file');
  253 + }
  254 + file_put_contents($outputFile, $this->getPhpCode());
  255 + }
  256 +}
  257 +
  258 +class PhpNamespace implements IteratorAggregate
  259 +{
  260 + private $namespace;
  261 + private $classes;
  262 +
  263 + public function __construct($namespace)
  264 + {
  265 + $this->namespace = $namespace;
  266 + $this->classes = array();
  267 + $this->useDirectives = new PhpUseDirectives($this);
  268 + }
  269 +
  270 + public static function extractName($fqn)
  271 + {
  272 + $nsSepLast = strrpos($fqn, '\\');
  273 + if ($nsSepLast === false) {
  274 + return $fqn;
  275 + }
  276 + $ns = substr($fqn, 0, $nsSepLast);
  277 +
  278 + return $ns !== '' ? $ns : null;
  279 + }
  280 +
  281 + public function addClass(PhpClass $class)
  282 + {
  283 + $this->classes[$class->getName()] = $class;
  284 + }
  285 +
  286 + public function getClass($className)
  287 + {
  288 + if (isset($this->classes[$className])) {
  289 + return $this->classes[$className];
  290 + }
  291 + }
  292 +
  293 + public function getClasses()
  294 + {
  295 + return array_values($this->classes);
  296 + }
  297 +
  298 + public function getIterator()
  299 + {
  300 + return new \ArrayIterator($this->getClasses());
  301 + }
  302 +
  303 + public function getUseDirectives()
  304 + {
  305 + return $this->useDirectives;
  306 + }
  307 +
  308 + public function getPhpCode()
  309 + {
  310 + return "namespace $this->namespace;\n";
  311 + }
  312 +
  313 + public function __toString()
  314 + {
  315 + return $this->namespace;
  316 + }
  317 +}
  318 +
  319 +class PhpUseDirectives implements Countable, IteratorAggregate
  320 +{
  321 + private $use;
  322 + private $aliases;
  323 + private $reverseAliases;
  324 + private $namespace;
  325 +
  326 + public function __construct(PhpNamespace $namespace)
  327 + {
  328 + $this->namespace = $namespace;
  329 + $this->use = array();
  330 + $this->aliases = array();
  331 + $this->reverseAliases = array();
  332 + }
  333 +
  334 + public function add($use, $as = null)
  335 + {
  336 + if (in_array($use, $this->use)) {
  337 + return;
  338 + }
  339 +
  340 + $rename = null;
  341 + $this->use[] = $use;
  342 + $aliasedClassName = $as ?: PhpClass::extractName($use);
  343 +
  344 + if (isset($this->aliases[$aliasedClassName])) {
  345 + $parentNs = $this->getParentNamespace();
  346 +
  347 + if ($parentNs && false !== $pos = strrpos($parentNs, '\\')) {
  348 + $parentNs = substr($parentNs, $pos);
  349 + }
  350 +
  351 + $newAlias = "{$parentNs}_{$aliasedClassName}";
  352 + $rename = (object) array(
  353 + 'namespace' => $this->namespace,
  354 + 'from' => $aliasedClassName,
  355 + 'to' => $newAlias,
  356 + );
  357 +
  358 + $this->aliases[$newAlias] = $use;
  359 + $as = $newAlias;
  360 + } else {
  361 + $this->aliases[$aliasedClassName] = $use;
  362 + }
  363 +
  364 + if ($as !== null) {
  365 + $this->reverseAliases[$use] = $as;
  366 + }
  367 +
  368 + return $rename;
  369 + }
  370 +
  371 + public function getList()
  372 + {
  373 + return $this->use;
  374 + }
  375 +
  376 + public function getIterator()
  377 + {
  378 + return new \ArrayIterator($this->getList());
  379 + }
  380 +
  381 + public function getPhpCode()
  382 + {
  383 + $reverseAliases = $this->reverseAliases;
  384 +
  385 + $reducer = function ($str, $use) use ($reverseAliases) {
  386 + if (isset($reverseAliases[$use])) {
  387 + return $str .= "use $use as {$reverseAliases[$use]};\n";
  388 + } else {
  389 + return $str .= "use $use;\n";
  390 + }
  391 + };
  392 +
  393 + return array_reduce($this->getList(), $reducer, '');
  394 + }
  395 +
  396 + public function getNamespace()
  397 + {
  398 + return $this->namespace;
  399 + }
  400 +
  401 + public function getParentNamespace()
  402 + {
  403 + if (false !== $pos = strrpos($this->namespace, '\\')) {
  404 + return substr($this->namespace, 0, $pos);
  405 + }
  406 +
  407 + return '';
  408 + }
  409 +
  410 + public function getFQN($className)
  411 + {
  412 + if (($nsSepFirst = strpos($className, '\\')) === false) {
  413 + if (isset($this->aliases[$className])) {
  414 + return $this->aliases[$className];
  415 + }
  416 +
  417 + return (string)$this->getNamespace() . "\\$className";
  418 + }
  419 +
  420 + if ($nsSepFirst != 0) {
  421 + throw new InvalidArgumentException("Partially qualified names are not supported");
  422 + }
  423 +
  424 + return $className;
  425 + }
  426 +
  427 + public function count()
  428 + {
  429 + return count($this->use);
  430 + }
  431 +}
  432 +
  433 +class PhpClass
  434 +{
  435 + const LICENSE_HEADER = <<<LICENSE
  436 +/*
  437 + * This file is part of the Predis package.
  438 + *
  439 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  440 + *
  441 + * For the full copyright and license information, please view the LICENSE
  442 + * file that was distributed with this source code.
  443 + */
  444 +LICENSE;
  445 +
  446 + private $namespace;
  447 + private $file;
  448 + private $body;
  449 + private $implements;
  450 + private $extends;
  451 + private $name;
  452 +
  453 + public function __construct(PhpNamespace $namespace, SplFileInfo $classFile)
  454 + {
  455 + $this->namespace = $namespace;
  456 + $this->file = $classFile;
  457 + $this->implements = array();
  458 + $this->extends = array();
  459 +
  460 + $this->extractData();
  461 + $namespace->addClass($this);
  462 + }
  463 +
  464 + public static function extractName($fqn)
  465 + {
  466 + $nsSepLast = strrpos($fqn, '\\');
  467 + if ($nsSepLast === false) {
  468 + return $fqn;
  469 + }
  470 +
  471 + return substr($fqn, $nsSepLast + 1);
  472 + }
  473 +
  474 + private function extractData()
  475 + {
  476 + $renames = array();
  477 + $useDirectives = $this->getNamespace()->getUseDirectives();
  478 +
  479 + $useExtractor = function ($m) use ($useDirectives, &$renames) {
  480 + array_shift($m);
  481 +
  482 + if (isset($m[1])) {
  483 + $m[1] = str_replace(" as ", '', $m[1]);
  484 + }
  485 +
  486 + if ($rename = call_user_func_array(array($useDirectives, 'add'), $m)) {
  487 + $renames[] = $rename;
  488 + }
  489 + };
  490 +
  491 + $classBuffer = stream_get_contents(fopen($this->getFile()->getPathname(), 'r'));
  492 +
  493 + $classBuffer = str_replace(self::LICENSE_HEADER, '', $classBuffer);
  494 +
  495 + $classBuffer = preg_replace('/<\?php\s?\\n\s?/', '', $classBuffer);
  496 + $classBuffer = preg_replace('/\s?\?>\n?/ms', '', $classBuffer);
  497 + $classBuffer = preg_replace('/namespace\s+[\w\d_\\\\]+;\s?/', '', $classBuffer);
  498 + $classBuffer = preg_replace_callback('/use\s+([\w\d_\\\\]+)(\s+as\s+.*)?;\s?\n?/', $useExtractor, $classBuffer);
  499 +
  500 + foreach ($renames as $rename) {
  501 + $classBuffer = str_replace($rename->from, $rename->to, $classBuffer);
  502 + }
  503 +
  504 + $this->body = trim($classBuffer);
  505 +
  506 + $this->extractHierarchy();
  507 + }
  508 +
  509 + private function extractHierarchy()
  510 + {
  511 + $implements = array();
  512 + $extends = array();
  513 +
  514 + $extractor = function ($iterator, $callback) {
  515 + $className = '';
  516 + $iterator->seek($iterator->key() + 1);
  517 +
  518 + while ($iterator->valid()) {
  519 + $token = $iterator->current();
  520 +
  521 + if (is_string($token)) {
  522 + if (preg_match('/\s?,\s?/', $token)) {
  523 + $callback(trim($className));
  524 + $className = '';
  525 + } else if ($token == '{') {
  526 + $callback(trim($className));
  527 + return;
  528 + }
  529 + }
  530 +
  531 + switch ($token[0]) {
  532 + case T_NS_SEPARATOR:
  533 + $className .= '\\';
  534 + break;
  535 +
  536 + case T_STRING:
  537 + $className .= $token[1];
  538 + break;
  539 +
  540 + case T_IMPLEMENTS:
  541 + case T_EXTENDS:
  542 + $callback(trim($className));
  543 + $iterator->seek($iterator->key() - 1);
  544 + return;
  545 + }
  546 +
  547 + $iterator->next();
  548 + }
  549 + };
  550 +
  551 + $tokens = token_get_all("<?php\n" . trim($this->getPhpCode()));
  552 + $iterator = new ArrayIterator($tokens);
  553 +
  554 + while ($iterator->valid()) {
  555 + $token = $iterator->current();
  556 + if (is_string($token)) {
  557 + $iterator->next();
  558 + continue;
  559 + }
  560 +
  561 + switch ($token[0]) {
  562 + case T_CLASS:
  563 + case T_INTERFACE:
  564 + $iterator->seek($iterator->key() + 2);
  565 + $tk = $iterator->current();
  566 + $this->name = $tk[1];
  567 + break;
  568 +
  569 + case T_IMPLEMENTS:
  570 + $extractor($iterator, function ($fqn) use (&$implements) {
  571 + $implements[] = $fqn;
  572 + });
  573 + break;
  574 +
  575 + case T_EXTENDS:
  576 + $extractor($iterator, function ($fqn) use (&$extends) {
  577 + $extends[] = $fqn;
  578 + });
  579 + break;
  580 + }
  581 +
  582 + $iterator->next();
  583 + }
  584 +
  585 + $this->implements = $this->guessFQN($implements);
  586 + $this->extends = $this->guessFQN($extends);
  587 + }
  588 +
  589 + public function guessFQN($classes)
  590 + {
  591 + $useDirectives = $this->getNamespace()->getUseDirectives();
  592 + return array_map(array($useDirectives, 'getFQN'), $classes);
  593 + }
  594 +
  595 + public function getImplementedInterfaces($all = false)
  596 + {
  597 + if ($all) {
  598 + return $this->implements;
  599 + }
  600 +
  601 + return array_filter(
  602 + $this->implements,
  603 + function ($cn) { return strpos($cn, 'Predis\\') === 0; }
  604 + );
  605 + }
  606 +
  607 + public function getExtendedClasses($all = false)
  608 + {
  609 + if ($all) {
  610 + return $this->extemds;
  611 + }
  612 +
  613 + return array_filter(
  614 + $this->extends,
  615 + function ($cn) { return strpos($cn, 'Predis\\') === 0; }
  616 + );
  617 + }
  618 +
  619 + public function getDependencies($all = false)
  620 + {
  621 + return array_merge(
  622 + $this->getImplementedInterfaces($all),
  623 + $this->getExtendedClasses($all)
  624 + );
  625 + }
  626 +
  627 + public function getNamespace()
  628 + {
  629 + return $this->namespace;
  630 + }
  631 +
  632 + public function getFile()
  633 + {
  634 + return $this->file;
  635 + }
  636 +
  637 + public function getName()
  638 + {
  639 + return $this->name;
  640 + }
  641 +
  642 + public function getFQN()
  643 + {
  644 + return (string)$this->getNamespace() . '\\' . $this->name;
  645 + }
  646 +
  647 + public function getPhpCode()
  648 + {
  649 + return $this->body;
  650 + }
  651 +
  652 + public function __toString()
  653 + {
  654 + return "class " . $this->getName() . '{ ... }';
  655 + }
  656 +}
  657 +
  658 +/* -------------------------------------------------------------------------- */
  659 +
  660 +$options = CommandLine::getOptions();
  661 +$predisFile = PredisFile::from($options['source'], $options['exclude']);
  662 +$predisFile->saveTo($options['output']);
  1 +{
  2 + "name": "predis/predis",
  3 + "type": "library",
  4 + "description": "Flexible and feature-complete Redis client for PHP and HHVM",
  5 + "keywords": ["nosql", "redis", "predis"],
  6 + "homepage": "http://github.com/predis/predis",
  7 + "license": "MIT",
  8 + "support": {
  9 + "issues": "https://github.com/predis/predis/issues"
  10 + },
  11 + "authors": [
  12 + {
  13 + "name": "Daniele Alessandri",
  14 + "email": "suppakilla@gmail.com",
  15 + "homepage": "http://clorophilla.net",
  16 + "role": "Creator & Maintainer"
  17 + },
  18 + {
  19 + "name": "Till Krüss",
  20 + "homepage": "https://till.im",
  21 + "role": "Maintainer"
  22 + }
  23 + ],
  24 + "funding": [
  25 + {
  26 + "type": "github",
  27 + "url": "https://github.com/sponsors/tillkruss"
  28 + }
  29 + ],
  30 + "require": {
  31 + "php": ">=5.3.9"
  32 + },
  33 + "require-dev": {
  34 + "phpunit/phpunit": "~4.8"
  35 + },
  36 + "suggest": {
  37 + "ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol",
  38 + "ext-curl": "Allows access to Webdis when paired with phpiredis"
  39 + },
  40 + "autoload": {
  41 + "psr-4": {
  42 + "Predis\\": "src/"
  43 + }
  44 + },
  45 + "scripts": {
  46 + "post-update-cmd": "@php -f tests/apply-patches.php"
  47 + }
  48 +}
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// Developers can implement Predis\Distribution\DistributorInterface to create
  15 +// their own distributors used by the client to distribute keys among a cluster
  16 +// of servers.
  17 +
  18 +use Predis\Cluster\Distributor\DistributorInterface;
  19 +use Predis\Cluster\Hash\HashGeneratorInterface;
  20 +use Predis\Cluster\PredisStrategy;
  21 +use Predis\Connection\Aggregate\PredisCluster;
  22 +
  23 +class NaiveDistributor implements DistributorInterface, HashGeneratorInterface
  24 +{
  25 + private $nodes;
  26 + private $nodesCount;
  27 +
  28 + public function __construct()
  29 + {
  30 + $this->nodes = array();
  31 + $this->nodesCount = 0;
  32 + }
  33 +
  34 + public function add($node, $weight = null)
  35 + {
  36 + $this->nodes[] = $node;
  37 + ++$this->nodesCount;
  38 + }
  39 +
  40 + public function remove($node)
  41 + {
  42 + $this->nodes = array_filter($this->nodes, function ($n) use ($node) {
  43 + return $n !== $node;
  44 + });
  45 +
  46 + $this->nodesCount = count($this->nodes);
  47 + }
  48 +
  49 + public function getSlot($hash)
  50 + {
  51 + return $this->nodesCount > 1 ? abs($hash % $this->nodesCount) : 0;
  52 + }
  53 +
  54 + public function getBySlot($slot)
  55 + {
  56 + return isset($this->nodes[$slot]) ? $this->nodes[$slot] : null;
  57 + }
  58 +
  59 + public function getByHash($hash)
  60 + {
  61 + if (!$this->nodesCount) {
  62 + throw new RuntimeException('No connections.');
  63 + }
  64 +
  65 + $slot = $this->getSlot($hash);
  66 + $node = $this->getBySlot($slot);
  67 +
  68 + return $node;
  69 + }
  70 +
  71 + public function get($value)
  72 + {
  73 + $hash = $this->hash($value);
  74 + $node = $this->getByHash($hash);
  75 +
  76 + return $node;
  77 + }
  78 +
  79 + public function hash($value)
  80 + {
  81 + return crc32($value);
  82 + }
  83 +
  84 + public function getHashGenerator()
  85 + {
  86 + return $this;
  87 + }
  88 +}
  89 +
  90 +$options = array(
  91 + 'cluster' => function () {
  92 + $distributor = new NaiveDistributor();
  93 + $strategy = new PredisStrategy($distributor);
  94 + $cluster = new PredisCluster($strategy);
  95 +
  96 + return $cluster;
  97 + },
  98 +);
  99 +
  100 +$client = new Predis\Client($multiple_servers, $options);
  101 +
  102 +for ($i = 0; $i < 100; ++$i) {
  103 + $client->set("key:$i", str_pad($i, 4, '0', 0));
  104 + $client->get("key:$i");
  105 +}
  106 +
  107 +$server1 = $client->getClientFor('first')->info();
  108 +$server2 = $client->getClientFor('second')->info();
  109 +
  110 +if (isset($server1['Keyspace'], $server2['Keyspace'])) {
  111 + $server1 = $server1['Keyspace'];
  112 + $server2 = $server2['Keyspace'];
  113 +}
  114 +
  115 +printf("Server '%s' has %d keys while server '%s' has %d keys.\n",
  116 + 'first', $server1['db15']['keys'], 'second', $server2['db15']['keys']
  117 +);
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// This is an example of how you can easily extend an existing connection class
  15 +// and trace the execution of commands for debugging purposes. This can be quite
  16 +// useful as a starting poing to understand how your application interacts with
  17 +// Redis.
  18 +
  19 +use Predis\Command\CommandInterface;
  20 +use Predis\Connection\StreamConnection;
  21 +
  22 +class SimpleDebuggableConnection extends StreamConnection
  23 +{
  24 + private $tstart = 0;
  25 + private $debugBuffer = array();
  26 +
  27 + public function connect()
  28 + {
  29 + $this->tstart = microtime(true);
  30 +
  31 + parent::connect();
  32 + }
  33 +
  34 + private function storeDebug(CommandInterface $command, $direction)
  35 + {
  36 + $firtsArg = $command->getArgument(0);
  37 + $timestamp = round(microtime(true) - $this->tstart, 4);
  38 +
  39 + $debug = $command->getId();
  40 + $debug .= isset($firtsArg) ? " $firtsArg " : ' ';
  41 + $debug .= "$direction $this";
  42 + $debug .= " [{$timestamp}s]";
  43 +
  44 + $this->debugBuffer[] = $debug;
  45 + }
  46 +
  47 + public function writeRequest(CommandInterface $command)
  48 + {
  49 + parent::writeRequest($command);
  50 +
  51 + $this->storeDebug($command, '->');
  52 + }
  53 +
  54 + public function readResponse(CommandInterface $command)
  55 + {
  56 + $response = parent::readResponse($command);
  57 + $this->storeDebug($command, '<-');
  58 +
  59 + return $response;
  60 + }
  61 +
  62 + public function getDebugBuffer()
  63 + {
  64 + return $this->debugBuffer;
  65 + }
  66 +}
  67 +
  68 +$options = array(
  69 + 'connections' => array(
  70 + 'tcp' => 'SimpleDebuggableConnection',
  71 + ),
  72 +);
  73 +
  74 +$client = new Predis\Client($single_server, $options);
  75 +$client->set('foo', 'bar');
  76 +$client->get('foo');
  77 +$client->info();
  78 +
  79 +var_export($client->getConnection()->getDebugBuffer());
  80 +
  81 +/* OUTPUT:
  82 +array (
  83 + 0 => 'SELECT 15 -> 127.0.0.1:6379 [0.0008s]',
  84 + 1 => 'SELECT 15 <- 127.0.0.1:6379 [0.001s]',
  85 + 2 => 'SET foo -> 127.0.0.1:6379 [0.001s]',
  86 + 3 => 'SET foo <- 127.0.0.1:6379 [0.0011s]',
  87 + 4 => 'GET foo -> 127.0.0.1:6379 [0.0013s]',
  88 + 5 => 'GET foo <- 127.0.0.1:6379 [0.0015s]',
  89 + 6 => 'INFO -> 127.0.0.1:6379 [0.0019s]',
  90 + 7 => 'INFO <- 127.0.0.1:6379 [0.0022s]',
  91 +)
  92 +*/
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// This is a basic example on how to use the Predis\DispatcherLoop class.
  15 +//
  16 +// To see this example in action you can just use redis-cli and publish some
  17 +// messages to the 'events' and 'control' channel, e.g.:
  18 +
  19 +// ./redis-cli
  20 +// PUBLISH events first
  21 +// PUBLISH events second
  22 +// PUBLISH events third
  23 +// PUBLISH control terminate_dispatcher
  24 +
  25 +// Create a client and disable r/w timeout on the socket
  26 +$client = new Predis\Client($single_server + array('read_write_timeout' => 0));
  27 +
  28 +// Return an initialized PubSub consumer instance from the client.
  29 +$pubsub = $client->pubSubLoop();
  30 +
  31 +// Create a dispatcher loop instance and attach a bunch of callbacks.
  32 +$dispatcher = new Predis\PubSub\DispatcherLoop($pubsub);
  33 +
  34 +// Demonstrate how to use a callable class as a callback for the dispatcher loop.
  35 +class EventsListener implements Countable
  36 +{
  37 + private $events;
  38 +
  39 + public function __construct()
  40 + {
  41 + $this->events = array();
  42 + }
  43 +
  44 + public function count()
  45 + {
  46 + return count($this->events);
  47 + }
  48 +
  49 + public function getEvents()
  50 + {
  51 + return $this->events;
  52 + }
  53 +
  54 + public function __invoke($payload)
  55 + {
  56 + $this->events[] = $payload;
  57 + }
  58 +}
  59 +
  60 +// Attach our callable class to the dispatcher.
  61 +$dispatcher->attachCallback('events', ($events = new EventsListener()));
  62 +
  63 +// Attach a function to control the dispatcher loop termination with a message.
  64 +$dispatcher->attachCallback('control', function ($payload) use ($dispatcher) {
  65 + if ($payload === 'terminate_dispatcher') {
  66 + $dispatcher->stop();
  67 + }
  68 +});
  69 +
  70 +// Run the dispatcher loop until the callback attached to the 'control' channel
  71 +// receives 'terminate_dispatcher' as a message.
  72 +$dispatcher->run();
  73 +
  74 +// Display our achievements!
  75 +echo "We received {$events->count()} messages!", PHP_EOL;
  76 +
  77 +// Say goodbye :-)
  78 +$version = redis_version($client->info());
  79 +echo "Goodbye from Redis $version!", PHP_EOL;
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +$client = new Predis\Client($single_server);
  15 +
  16 +// Plain old SET and GET example...
  17 +$client->set('library', 'predis');
  18 +$response = $client->get('library');
  19 +
  20 +var_export($response); echo PHP_EOL;
  21 +/* OUTPUT: 'predis' */
  22 +
  23 +// Redis has the MSET and MGET commands to set or get multiple keys in one go,
  24 +// cases like this Predis accepts arguments for variadic commands both as a list
  25 +// of arguments or an array containing all of the keys and/or values.
  26 +$mkv = array(
  27 + 'uid:0001' => '1st user',
  28 + 'uid:0002' => '2nd user',
  29 + 'uid:0003' => '3rd user',
  30 +);
  31 +
  32 +$client->mset($mkv);
  33 +$response = $client->mget(array_keys($mkv));
  34 +
  35 +var_export($response); echo PHP_EOL;
  36 +/* OUTPUT:
  37 +array (
  38 + 0 => '1st user',
  39 + 1 => '2nd user',
  40 + 2 => '3rd user',
  41 +) */
  42 +
  43 +// Predis can also send "raw" commands to Redis. The difference between sending
  44 +// commands to Redis the usual way and the "raw" way is that in the latter case
  45 +// their arguments are not filtered nor responses coming from Redis are parsed.
  46 +
  47 +$response = $client->executeRaw(array(
  48 + 'MGET', 'uid:0001', 'uid:0002', 'uid:0003',
  49 +));
  50 +
  51 +var_export($response); echo PHP_EOL;
  52 +/* OUTPUT:
  53 +array (
  54 + 0 => '1st user',
  55 + 1 => '2nd user',
  56 + 2 => '3rd user',
  57 +) */
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// Predis can prefix keys found in commands arguments before sending commands to
  15 +// Redis, even for complex commands such as SORT, ZUNIONSTORE and ZINTERSTORE.
  16 +// Prefixing keys can be useful to create user-level namespaces for you keyspace
  17 +// thus reducing the need for separate logical databases in certain scenarios.
  18 +
  19 +$client = new Predis\Client($single_server, array('prefix' => 'nrk:'));
  20 +
  21 +$client->mset(array('foo' => 'bar', 'lol' => 'wut'));
  22 +var_export($client->mget('foo', 'lol'));
  23 +/*
  24 +array (
  25 + 0 => 'bar',
  26 + 1 => 'wut',
  27 +)
  28 +*/
  29 +
  30 +var_export($client->keys('*'));
  31 +/*
  32 +array (
  33 + 0 => 'nrk:foo',
  34 + 1 => 'nrk:lol',
  35 +)
  36 +*/
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// This example will not work with versions of Redis < 2.6.
  15 +//
  16 +// Additionally to the EVAL command defined in the current development profile,
  17 +// the Predis\Command\ScriptCommand class can be used to build an higher level
  18 +// abstraction for "scriptable" commands so that they will appear just like any
  19 +// other command on the client-side. This is a quick example used to implement
  20 +// INCREX.
  21 +
  22 +use Predis\Command\ScriptCommand;
  23 +
  24 +class IncrementExistingKeysBy extends ScriptCommand
  25 +{
  26 + public function getKeysCount()
  27 + {
  28 + // Tell Predis to use all the arguments but the last one as arguments
  29 + // for KEYS. The last one will be used to populate ARGV.
  30 + return -1;
  31 + }
  32 +
  33 + public function getScript()
  34 + {
  35 + return <<<LUA
  36 +local cmd, insert = redis.call, table.insert
  37 +local increment, results = ARGV[1], { }
  38 +
  39 +for idx, key in ipairs(KEYS) do
  40 + if cmd('exists', key) == 1 then
  41 + insert(results, idx, cmd('incrby', key, increment))
  42 + else
  43 + insert(results, idx, false)
  44 + end
  45 +end
  46 +
  47 +return results
  48 +LUA;
  49 + }
  50 +}
  51 +
  52 +$client = new Predis\Client($single_server, array(
  53 + 'profile' => function ($options) {
  54 + $profile = $options->getDefault('profile');
  55 + $profile->defineCommand('increxby', 'IncrementExistingKeysBy');
  56 +
  57 + return $profile;
  58 + },
  59 +));
  60 +
  61 +$client->mset('foo', 10, 'foobar', 100);
  62 +
  63 +var_export($client->increxby('foo', 'foofoo', 'foobar', 50));
  64 +
  65 +/*
  66 +array (
  67 + 0 => 60,
  68 + 1 => NULL,
  69 + 2 => 150,
  70 +)
  71 +*/
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// This is a basic example on how to use the Predis\Monitor\Consumer class. You
  15 +// can use redis-cli to send commands to the same Redis instance your client is
  16 +// connected to, and then type "ECHO QUIT_MONITOR" in redis-cli when you want to
  17 +// exit the monitor loop and terminate this script in a graceful way.
  18 +
  19 +// Create a client and disable r/w timeout on the socket.
  20 +$client = new Predis\Client($single_server + array('read_write_timeout' => 0));
  21 +
  22 +// Use only one instance of DateTime, we will update the timestamp later.
  23 +$timestamp = new DateTime();
  24 +
  25 +foreach (($monitor = $client->monitor()) as $event) {
  26 + $timestamp->setTimestamp((int) $event->timestamp);
  27 +
  28 + // If we notice a ECHO command with the message QUIT_MONITOR, we stop the
  29 + // monitor consumer and then break the loop.
  30 + if ($event->command === 'ECHO' && $event->arguments === '"QUIT_MONITOR"') {
  31 + echo 'Exiting the monitor loop...', PHP_EOL;
  32 + $monitor->stop();
  33 + break;
  34 + }
  35 +
  36 + echo "* Received {$event->command} on DB {$event->database} at {$timestamp->format(DateTime::W3C)}", PHP_EOL;
  37 + if (isset($event->arguments)) {
  38 + echo " Arguments: {$event->arguments}", PHP_EOL;
  39 + }
  40 +}
  41 +
  42 +// Say goodbye :-)
  43 +$version = redis_version($client->info());
  44 +echo "Goodbye from Redis $version!", PHP_EOL;
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// When you have a whole set of consecutive commands to send to a redis server,
  15 +// you can use a pipeline to dramatically improve performances. Pipelines can
  16 +// greatly reduce the effects of network round-trips.
  17 +
  18 +$client = new Predis\Client($single_server);
  19 +
  20 +$responses = $client->pipeline(function ($pipe) {
  21 + $pipe->flushdb();
  22 + $pipe->incrby('counter', 10);
  23 + $pipe->incrby('counter', 30);
  24 + $pipe->exists('counter');
  25 + $pipe->get('counter');
  26 + $pipe->mget('does_not_exist', 'counter');
  27 +});
  28 +
  29 +var_export($responses);
  30 +
  31 +/* OUTPUT:
  32 +array (
  33 + 0 => Predis\Response\Status::__set_state(array(
  34 + 'payload' => 'OK',
  35 + )),
  36 + 1 => 10,
  37 + 2 => 40,
  38 + 3 => true,
  39 + 4 => '40',
  40 + 5 => array (
  41 + 0 => NULL,
  42 + 1 => '40',
  43 + ),
  44 +)
  45 +*/
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// Starting from Redis 2.0 clients can subscribe and listen for events published
  15 +// on certain channels using a Publish/Subscribe (PUB/SUB) approach.
  16 +
  17 +// Create a client and disable r/w timeout on the socket
  18 +$client = new Predis\Client($single_server + array('read_write_timeout' => 0));
  19 +
  20 +// Initialize a new pubsub consumer.
  21 +$pubsub = $client->pubSubLoop();
  22 +
  23 +// Subscribe to your channels
  24 +$pubsub->subscribe('control_channel', 'notifications');
  25 +
  26 +// Start processing the pubsup messages. Open a terminal and use redis-cli
  27 +// to push messages to the channels. Examples:
  28 +// ./redis-cli PUBLISH notifications "this is a test"
  29 +// ./redis-cli PUBLISH control_channel quit_loop
  30 +foreach ($pubsub as $message) {
  31 + switch ($message->kind) {
  32 + case 'subscribe':
  33 + echo "Subscribed to {$message->channel}", PHP_EOL;
  34 + break;
  35 +
  36 + case 'message':
  37 + if ($message->channel == 'control_channel') {
  38 + if ($message->payload == 'quit_loop') {
  39 + echo 'Aborting pubsub loop...', PHP_EOL;
  40 + $pubsub->unsubscribe();
  41 + } else {
  42 + echo "Received an unrecognized command: {$message->payload}.", PHP_EOL;
  43 + }
  44 + } else {
  45 + echo "Received the following message from {$message->channel}:",
  46 + PHP_EOL, " {$message->payload}", PHP_EOL, PHP_EOL;
  47 + }
  48 + break;
  49 + }
  50 +}
  51 +
  52 +// Always unset the pubsub consumer instance when you are done! The
  53 +// class destructor will take care of cleanups and prevent protocol
  54 +// desynchronizations between the client and the server.
  55 +unset($pubsub);
  56 +
  57 +// Say goodbye :-)
  58 +$version = redis_version($client->info());
  59 +echo "Goodbye from Redis $version!", PHP_EOL;
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +use Predis\Collection\Iterator;
  15 +
  16 +// Starting from Redis 2.8, clients can iterate incrementally over collections
  17 +// without blocking the server like it happens when a command such as KEYS is
  18 +// executed on a Redis instance storing millions of keys. These commands are:
  19 +//
  20 +// - SCAN (iterates over the keyspace)
  21 +// - SSCAN (iterates over members of a set)
  22 +// - ZSCAN (iterates over members and ranks of a sorted set)
  23 +// - HSCAN (iterates over fields and values of an hash).
  24 +
  25 +// Predis provides a specialized abstraction for each command based on standard
  26 +// SPL iterators making it possible to easily consume SCAN-based iterations in
  27 +// your PHP code.
  28 +//
  29 +// See http://redis.io/commands/scan for more details.
  30 +//
  31 +
  32 +// Create a client using `2.8` as a server profile (needs Redis 2.8!)
  33 +$client = new Predis\Client($single_server, array('profile' => '2.8'));
  34 +
  35 +// Prepare some keys for our example
  36 +$client->del('predis:set', 'predis:zset', 'predis:hash');
  37 +for ($i = 0; $i < 5; ++$i) {
  38 + $client->sadd('predis:set', "member:$i");
  39 + $client->zadd('predis:zset', -$i, "member:$i");
  40 + $client->hset('predis:hash', "field:$i", "value:$i");
  41 +}
  42 +
  43 +// === Keyspace iterator based on SCAN ===
  44 +echo 'Scan the keyspace matching only our prefixed keys:', PHP_EOL;
  45 +foreach (new Iterator\Keyspace($client, 'predis:*') as $key) {
  46 + echo " - $key", PHP_EOL;
  47 +}
  48 +
  49 +/* OUTPUT
  50 +Scan the keyspace matching only our prefixed keys:
  51 + - predis:zset
  52 + - predis:set
  53 + - predis:hash
  54 +*/
  55 +
  56 +// === Set iterator based on SSCAN ===
  57 +echo 'Scan members of `predis:set`:', PHP_EOL;
  58 +foreach (new Iterator\SetKey($client, 'predis:set') as $member) {
  59 + echo " - $member", PHP_EOL;
  60 +}
  61 +
  62 +/* OUTPUT
  63 +Scan members of `predis:set`:
  64 + - member:1
  65 + - member:4
  66 + - member:0
  67 + - member:3
  68 + - member:2
  69 +*/
  70 +
  71 +// === Sorted set iterator based on ZSCAN ===
  72 +echo 'Scan members and ranks of `predis:zset`:', PHP_EOL;
  73 +foreach (new Iterator\SortedSetKey($client, 'predis:zset') as $member => $rank) {
  74 + echo " - $member [rank: $rank]", PHP_EOL;
  75 +}
  76 +
  77 +/* OUTPUT
  78 +Scan members and ranks of `predis:zset`:
  79 + - member:4 [rank: -4]
  80 + - member:3 [rank: -3]
  81 + - member:2 [rank: -2]
  82 + - member:1 [rank: -1]
  83 + - member:0 [rank: 0]
  84 +*/
  85 +
  86 +// === Hash iterator based on HSCAN ===
  87 +echo 'Scan fields and values of `predis:hash`:', PHP_EOL;
  88 +foreach (new Iterator\HashKey($client, 'predis:hash') as $field => $value) {
  89 + echo " - $field => $value", PHP_EOL;
  90 +}
  91 +
  92 +/* OUTPUT
  93 +Scan fields and values of `predis:hash`:
  94 + - field:0 => value:0
  95 + - field:1 => value:1
  96 + - field:2 => value:2
  97 + - field:3 => value:3
  98 + - field:4 => value:4
  99 +*/
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// Predis allows to set Lua scripts as read-only operations for replication.
  15 +// This works for both EVAL and EVALSHA and also for the client-side abstraction
  16 +// built upon them (Predis\Command\ScriptCommand). This example shows a slightly
  17 +// more complex configuration that injects a new script command in the server
  18 +// profile used by the new client instance and marks it marks it as a read-only
  19 +// operation for replication so that it will be executed on slaves.
  20 +
  21 +use Predis\Command\ScriptCommand;
  22 +use Predis\Connection\Aggregate\MasterSlaveReplication;
  23 +use Predis\Replication\ReplicationStrategy;
  24 +
  25 +// ------------------------------------------------------------------------- //
  26 +
  27 +// Define a new script command that returns all the fields of a variable number
  28 +// of hashes with a single roundtrip.
  29 +
  30 +class HashMultipleGetAll extends ScriptCommand
  31 +{
  32 + const BODY = <<<LUA
  33 +local hashes = {}
  34 +for _, key in pairs(KEYS) do
  35 + table.insert(hashes, key)
  36 + table.insert(hashes, redis.call('hgetall', key))
  37 +end
  38 +return hashes
  39 +LUA;
  40 +
  41 + public function getScript()
  42 + {
  43 + return self::BODY;
  44 + }
  45 +}
  46 +
  47 +// ------------------------------------------------------------------------- //
  48 +
  49 +$parameters = array(
  50 + 'tcp://127.0.0.1:6379/?alias=master',
  51 + 'tcp://127.0.0.1:6380/?alias=slave',
  52 +);
  53 +
  54 +$options = array(
  55 + 'profile' => function ($options, $option) {
  56 + $profile = $options->getDefault($option);
  57 + $profile->defineCommand('hmgetall', 'HashMultipleGetAll');
  58 +
  59 + return $profile;
  60 + },
  61 + 'replication' => function () {
  62 + $strategy = new ReplicationStrategy();
  63 + $strategy->setScriptReadOnly(HashMultipleGetAll::BODY);
  64 +
  65 + $replication = new MasterSlaveReplication($strategy);
  66 +
  67 + return $replication;
  68 + },
  69 +);
  70 +
  71 +// ------------------------------------------------------------------------- //
  72 +
  73 +$client = new Predis\Client($parameters, $options);
  74 +
  75 +// Execute the following commands on the master server using redis-cli:
  76 +// $ ./redis-cli HMSET metavars foo bar hoge piyo
  77 +// $ ./redis-cli HMSET servers master host1 slave host2
  78 +
  79 +$hashes = $client->hmgetall('metavars', 'servers');
  80 +
  81 +$replication = $client->getConnection();
  82 +$stillOnSlave = $replication->getCurrent() === $replication->getConnectionById('slave');
  83 +
  84 +echo 'Is still on slave? ', $stillOnSlave ? 'YES!' : 'NO!', PHP_EOL;
  85 +var_export($hashes);
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// Predis supports redis-sentinel to provide high availability in master / slave
  15 +// scenarios. The only but relevant difference with a basic replication scenario
  16 +// is that sentinel servers can manage the master server and its slaves based on
  17 +// their state, which means that they are able to provide an authoritative and
  18 +// updated configuration to clients thus avoiding static configurations for the
  19 +// replication servers and their roles.
  20 +
  21 +// Instead of connection parameters pointing to redis nodes, we provide a list
  22 +// of instances of redis-sentinel. Users should always provide a timeout value
  23 +// low enough to not hinder operations just in case a sentinel is unreachable
  24 +// but Predis uses a default value of 100 milliseconds for sentinel parameters
  25 +// without an explicit timeout value.
  26 +//
  27 +// NOTE: in real-world scenarios sentinels should be running on different hosts!
  28 +$sentinels = array(
  29 + 'tcp://127.0.0.1:5380?timeout=0.100',
  30 + 'tcp://127.0.0.1:5381?timeout=0.100',
  31 + 'tcp://127.0.0.1:5382?timeout=0.100',
  32 +);
  33 +
  34 +$client = new Predis\Client($sentinels, array(
  35 + 'replication' => 'sentinel',
  36 + 'service' => 'mymaster',
  37 +));
  38 +
  39 +// Read operation.
  40 +$exists = $client->exists('foo') ? 'yes' : 'no';
  41 +$current = $client->getConnection()->getCurrent()->getParameters();
  42 +echo "Does 'foo' exist on {$current->alias}? $exists.", PHP_EOL;
  43 +
  44 +// Write operation.
  45 +$client->set('foo', 'bar');
  46 +$current = $client->getConnection()->getCurrent()->getParameters();
  47 +echo "Now 'foo' has been set to 'bar' on {$current->alias}!", PHP_EOL;
  48 +
  49 +// Read operation.
  50 +$bar = $client->get('foo');
  51 +$current = $client->getConnection()->getCurrent()->getParameters();
  52 +echo "We fetched 'foo' from {$current->alias} and its value is '$bar'.", PHP_EOL;
  53 +
  54 +/* OUTPUT:
  55 +Does 'foo' exist on slave-127.0.0.1:6381? yes.
  56 +Now 'foo' has been set to 'bar' on master!
  57 +We fetched 'foo' from master and its value is 'bar'.
  58 +*/
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// Predis supports master / slave replication scenarios where write operations
  15 +// are performed on the master server and read operations are executed against
  16 +// one of the slaves. The behavior of commands or EVAL scripts can be customized
  17 +// at will. As soon as a write operation is performed the client switches to the
  18 +// master server for all the subsequent requests (either reads and writes).
  19 +//
  20 +// This example must be executed using the second Redis server configured as the
  21 +// slave of the first one (see the "SLAVEOF" command).
  22 +//
  23 +
  24 +$parameters = array(
  25 + 'tcp://127.0.0.1:6379?database=15&alias=master',
  26 + 'tcp://127.0.0.1:6380?database=15&alias=slave',
  27 +);
  28 +
  29 +$options = array('replication' => true);
  30 +
  31 +$client = new Predis\Client($parameters, $options);
  32 +
  33 +// Read operation.
  34 +$exists = $client->exists('foo') ? 'yes' : 'no';
  35 +$current = $client->getConnection()->getCurrent()->getParameters();
  36 +echo "Does 'foo' exist on {$current->alias}? $exists.", PHP_EOL;
  37 +
  38 +// Write operation.
  39 +$client->set('foo', 'bar');
  40 +$current = $client->getConnection()->getCurrent()->getParameters();
  41 +echo "Now 'foo' has been set to 'bar' on {$current->alias}!", PHP_EOL;
  42 +
  43 +// Read operation.
  44 +$bar = $client->get('foo');
  45 +$current = $client->getConnection()->getCurrent()->getParameters();
  46 +echo "We fetched 'foo' from {$current->alias} and its value is '$bar'.", PHP_EOL;
  47 +
  48 +/* OUTPUT:
  49 +Does 'foo' exist on slave? yes.
  50 +Now 'foo' has been set to 'bar' on master!
  51 +We fetched 'foo' from master and its value is 'bar'.
  52 +*/
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// This example demonstrates how to use Predis to save PHP sessions on Redis.
  15 +//
  16 +// The value of `session.gc_maxlifetime` in `php.ini` will be used by default as
  17 +// the TTL for keys holding session data but this value can be overridden when
  18 +// creating the session handler instance using the `gc_maxlifetime` option.
  19 +//
  20 +// NOTE: this class requires PHP >= 5.4 but can be used on PHP 5.3 if a polyfill
  21 +// for SessionHandlerInterface is provided either by you or an external package
  22 +// like `symfony/http-foundation`.
  23 +//
  24 +// See http://www.php.net/class.sessionhandlerinterface.php for more details.
  25 +//
  26 +
  27 +if (!interface_exists('SessionHandlerInterface')) {
  28 + die('ATTENTION: the session handler implemented by Predis requires PHP >= 5.4.0 '.
  29 + "or a polyfill for SessionHandlerInterface provided by an external package.\n");
  30 +}
  31 +
  32 +// Instantiate a new client just like you would normally do. Using a prefix for
  33 +// keys will effectively prefix all session keys with the specified string.
  34 +$client = new Predis\Client($single_server, array('prefix' => 'sessions:'));
  35 +
  36 +// Set `gc_maxlifetime` to specify a time-to-live of 5 seconds for session keys.
  37 +$handler = new Predis\Session\Handler($client, array('gc_maxlifetime' => 5));
  38 +
  39 +// Register the session handler.
  40 +$handler->register();
  41 +
  42 +// We just set a fixed session ID only for the sake of our example.
  43 +session_id('example_session_id');
  44 +
  45 +session_start();
  46 +
  47 +if (isset($_SESSION['foo'])) {
  48 + echo "Session has `foo` set to {$_SESSION['foo']}", PHP_EOL;
  49 +} else {
  50 + $_SESSION['foo'] = $value = mt_rand();
  51 + echo "Empty session, `foo` has been set with $value", PHP_EOL;
  52 +}
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +if (PHP_SAPI !== 'cli') {
  13 + die("Example scripts are meant to be executed locally via CLI.");
  14 +}
  15 +
  16 +require __DIR__.'/../autoload.php';
  17 +
  18 +function redis_version($info)
  19 +{
  20 + if (isset($info['Server']['redis_version'])) {
  21 + return $info['Server']['redis_version'];
  22 + } elseif (isset($info['redis_version'])) {
  23 + return $info['redis_version'];
  24 + } else {
  25 + return 'unknown version';
  26 + }
  27 +}
  28 +
  29 +$single_server = array(
  30 + 'host' => '127.0.0.1',
  31 + 'port' => 6379,
  32 + 'database' => 15,
  33 +);
  34 +
  35 +$multiple_servers = array(
  36 + array(
  37 + 'host' => '127.0.0.1',
  38 + 'port' => 6379,
  39 + 'database' => 15,
  40 + 'alias' => 'first',
  41 + ),
  42 + array(
  43 + 'host' => '127.0.0.1',
  44 + 'port' => 6380,
  45 + 'database' => 15,
  46 + 'alias' => 'second',
  47 + ),
  48 +);
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +require __DIR__.'/shared.php';
  13 +
  14 +// This is an implementation of an atomic client-side ZPOP using the support for
  15 +// check-and-set (CAS) operations with MULTI/EXEC transactions, as described in
  16 +// "WATCH explained" from http://redis.io/topics/transactions
  17 +//
  18 +// First, populate your database with a tiny sample data set:
  19 +//
  20 +// ./redis-cli
  21 +// SELECT 15
  22 +// ZADD zset 1 a 2 b 3 c
  23 +//
  24 +// Then execute this script four times and see its output.
  25 +//
  26 +
  27 +function zpop($client, $key)
  28 +{
  29 + $element = null;
  30 + $options = array(
  31 + 'cas' => true, // Initialize with support for CAS operations
  32 + 'watch' => $key, // Key that needs to be WATCHed to detect changes
  33 + 'retry' => 3, // Number of retries on aborted transactions, after
  34 + // which the client bails out with an exception.
  35 + );
  36 +
  37 + $client->transaction($options, function ($tx) use ($key, &$element) {
  38 + @list($element) = $tx->zrange($key, 0, 0);
  39 +
  40 + if (isset($element)) {
  41 + $tx->multi(); // With CAS, MULTI *must* be explicitly invoked.
  42 + $tx->zrem($key, $element);
  43 + }
  44 + });
  45 +
  46 + return $element;
  47 +}
  48 +
  49 +$client = new Predis\Client($single_server);
  50 +$zpopped = zpop($client, 'zset');
  51 +
  52 +echo isset($zpopped) ? "ZPOPed $zpopped" : 'Nothing to ZPOP!', PHP_EOL;
  1 +; This file is meant to be used with Onion http://c9s.github.com/Onion/
  2 +; For instructions on how to build a PEAR package of Predis please follow
  3 +; the instructions at this URL:
  4 +;
  5 +; https://github.com/c9s/Onion#a-quick-tutorial-for-building-pear-package
  6 +;
  7 +
  8 +[package]
  9 +name = "Predis"
  10 +desc = "Flexible and feature-complete Redis client for PHP and HHVM"
  11 +homepage = "http://github.com/nrk/predis"
  12 +license = "MIT"
  13 +version = "1.1.10"
  14 +stability = "stable"
  15 +channel = "pear.nrk.io"
  16 +
  17 +author = "Daniele Alessandri \"nrk\" <suppakilla@gmail.com>"
  18 +
  19 +[require]
  20 +php = ">= 5.3.9"
  21 +pearinstaller = "1.4.1"
  22 +
  23 +[roles]
  24 +*.xml.dist = test
  25 +*.md = doc
  26 +LICENSE = doc
  27 +
  28 +[optional phpiredis]
  29 +hint = "Add support for faster protocol handling with phpiredis"
  30 +extensions[] = socket
  31 +extensions[] = phpiredis
  32 +
  33 +[optional webdis]
  34 +hint = "Add support for Webdis"
  35 +extensions[] = curl
  36 +extensions[] = phpiredis
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of the Predis package.
  5 + *
  6 + * (c) Daniele Alessandri <suppakilla@gmail.com>
  7 + *
  8 + * For the full copyright and license information, please view the LICENSE
  9 + * file that was distributed with this source code.
  10 + */
  11 +
  12 +namespace Predis;
  13 +
  14 +/**
  15 + * Implements a lightweight PSR-0 compliant autoloader for Predis.
  16 + *
  17 + * @author Eric Naeseth <eric@thumbtack.com>
  18 + * @author Daniele Alessandri <suppakilla@gmail.com>
  19 + */
  20 +class Autoloader
  21 +{
  22 + private $directory;
  23 + private $prefix;
  24 + private $prefixLength;
  25 +
  26 + /**
  27 + * @param string $baseDirectory Base directory where the source files are located.
  28 + */
  29 + public function __construct($baseDirectory = __DIR__)
  30 + {
  31 + $this->directory = $baseDirectory;
  32 + $this->prefix = __NAMESPACE__.'\\';
  33 + $this->prefixLength = strlen($this->prefix);
  34 + }
  35 +
  36 + /**
  37 + * Registers the autoloader class with the PHP SPL autoloader.
  38 + *
  39 + * @param bool $prepend Prepend the autoloader on the stack instead of appending it.
  40 + */
  41 + public static function register($prepend = false)
  42 + {
  43 + spl_autoload_register(array(new self(), 'autoload'), true, $prepend);
  44 + }
  45 +
  46 + /**
  47 + * Loads a class from a file using its fully qualified name.
  48 + *
  49 + * @param string $className Fully qualified name of a class.
  50 + */
  51 + public function autoload($className)
  52 + {
  53 + if (0 === strpos($className, $this->prefix)) {
  54 + $parts = explode('\\', substr($className, $this->prefixLength));
  55 + $filepath = $this->directory.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts).'.php';
  56 +
  57 + if (is_file($filepath)) {
  58 + require $filepath;
  59 + }
  60 + }
  61 + }
  62 +}