瞎想使用redis

  1 #!/usr/bin/php -q
  2 <?php
  3 /*ini_set('date.timezone','Asia/Shanghai');*/
  4 //数据库连接
  5 /*function getDBConn($dbname){
  6     $config = include(dirname(dirname(dirname(__FILE__))).'/database.php');//数据库配置
  7     $dbh = new PDO('mysql:host=localhost;port=3306;dbname='.$dbname.'',$config['username'],$config['password']);
  8     $dbh->query("SET NAMES UTF8");
  9     return $dbh;
 10 }
 11 $db = getDBConn('api');*/
 12 
 13 /*function getRDMC(){
 14     $redis=new Redis();
 15     $redis->connect("127.0.0.1",6379);
 16     $redis->auth("xxxxxx");//redis密码
 17     return $redis;
 18 }
 19 $redis=getRDMC();*/
 20 
 21 //增加集合元素
 22 //$redis->sAdd("1002","1","2","3","4","5","6","7","2");
 23 
 24 //获得集合全部元素
 25 //$uid=$redis->sMembers("1002");
 26 //print_r($uid);
 27 
 28 //随机获得集合n个元素
 29 //$id=$redis -> sRandMember('1002',3);
 30 
 31 /*foreach($id as $val){
 32     //删除集合指定元素
 33     $redis -> sRem('1002',$val);
 34 }*/
 35 
 36 //获得集合的元素总数
 37 //$redis -> sCard('1002');
 38 
 39 /*$uid=$redis->sMembers("1002");
 40 print_r($uid);*/
 41 
 42 //删除某个键
 43 /*$redis->del("1002");*/
 44 
 45 
 46 
 47 class aredis{
 48     //入口
 49     public function init($data){
 50 
 51         $redis=$this->getRDMC();
 52 
 53 //        $key = '1004-16';
 54 //        $data =  array(
 55 //            array('hdel','tasks',$key),
 56 //            array('hDel','taskuptime',$key),
 57 //            array('del',$key),
 58 //        );
 59 
 60         if($data){
 61             foreach($data as $key => $value){
 62                 $info = array();
 63                 foreach($value as $value_key  =>  $value_value){
 64                     $info[$value_key] = $value_value;
 65                 }
 66                 $action=array_shift($info);
67 if(count($info) == '1'){ 68 $a = $redis -> $action("$info[0]"); 69 $adminlog = fopen('/var/www/result.txt', "a") or exit("无法打开文件!"); 70 fwrite($adminlog, '$a ====' ."\n". var_export($a, true) . "\n"); 71 fclose($adminlog); 72 73 }elseif(count($info) == '2'){ 74 $b = $redis -> $action("$info[0]","$info[1]"); 75 76 $adminlog = fopen('/var/www/result.txt', "a") or exit("无法打开文件!"); 77 fwrite($adminlog, '$b ====' ."\n". var_export($b, true) . "\n"); 78 fclose($adminlog); 79 } 80 } 81 } 82 83 } 84 85 private function getRDMC(){ 86 $redis=new Redis(); 87 $redis->connect("127.0.0.1",6379); 88 $redis->auth("pbx.2019"); 89 return $redis; 90 } 91 } 92 93 94 $data1=$argv[1];// 获取数据地址; 95 $aredis = new aredis(); 96 $data = json_decode($data1,true); 97 $aredis->init($data); 98 99 100 101 102 103 104 105 106 107 108 ?>

 

posted @ 2019-03-07 09:54  终究是乌云遮了天  阅读(170)  评论(0编辑  收藏  举报