connection() публичный статический Метод

Get a specific Redis connection instance.
public static connection ( string $name = 'default' ) : Predis\ClientInterface | null
$name string
Результат Predis\ClientInterface | null
Пример #1
0
 function __construct(redisModel $subject, $objectName, $index)
 {
     $this->redis = Redis::connection();
     $this->subject = $subject;
     $this->objectName = $objectName;
     $this->objectIndex = $index;
 }
Пример #2
0
 function __construct($token, $withCar = false)
 {
     $this->token = $token;
     $this->withCar = $withCar;
     $this->redis = Redis::connection();
     $conn = parse_url(getenv('REDISCLOUD_URL'));
     if (isset($conn['pass'])) {
         $this->redis->auth($conn['pass']);
     }
     $this->data = json_decode($this->redis->get($this->token), true) ?: ['new' => ['chats' => [], 'carChats' => [], 'posts' => [], 'comments' => [], 'emergencies' => []]];
 }
Пример #3
0
 public function cities()
 {
     $this->locale = in_array(Request::header('Locale'), $this->avaibleLocales) ? Request::header('Locale') : $this->avaibleLocales[0];
     $configDate = Cache::get('database.refs-version');
     $redis = Redis::connection();
     $conn = parse_url(getenv('REDISCLOUD_URL'));
     if (isset($conn['pass'])) {
         $redis->auth($conn['pass']);
     }
     return $this->respond(Cache::get("cities-{$configDate}-{$this->locale}"));
 }
Пример #4
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     echo 1;
     //
     $redis = Redis::connection('default');
     $key = 'CCQ_test';
     $value = '2333333';
     $redis->set($key, $value);
     //		dd(Redis::get($key));
     //		$res = Redis::get($key);
     $res = $redis->get($key);
     var_dump($res);
 }
 /**
  * Redis cleanup function
  * 不要になったKeyを削除
  * @return void
  */
 public function getDisableKey()
 {
     $redis = \Redis::connection('default');
     $previous = date("Ymd", strtotime("- 1day", strtotime(date("Ymd"))));
     $result = $redis->keys(self::SET_PREFIX . "{$previous}*");
     if (count($result)) {
         $redis->pipeline(function ($pipe) use($result) {
             foreach ($result as $row) {
                 $pipe->del($row);
             }
         });
     }
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     $connection = \Redis::connection();
     try {
         $serverInfo = $connection->info();
         $isConnected = true;
     } catch (\Exception $e) {
         \Session::flash('error', 'Check Redis server connection. ' . $e->getMessage());
         $serverInfo = null;
         $isConnected = false;
     }
     \View::share(compact('isConnected', 'serverInfo'));
 }
Пример #7
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     //
     $redis = \Redis::connection();
     $info = ['from' => $this->from, 'to' => $this->to, 'content' => $this->content, 'createTime' => $this->time];
     //$res=DB::insert('insert into msg (`from`,`to`,content,createTime) values( :from, :to, :content,:createTime)',$info);
     Log::info('test jobs ----------------------------------------------');
     echo "hohoohoho";
     /*
              while($a=$redis->rpop("msg_queu")){
                   $info=json_decode($a,true);
     			  
     			  
                   $mysql=new mysqli("host","user","pwd","db");
                   $sql="insert into msg (to,content,from,time) value( ".$info['toid'].",".$info['content'].","."$info['fromid'].",".$info['time']);
                   $res=$mysql->query($sql);
                   //  do something          
              }*/
 }
Пример #8
0
 public static function notice($text, $uid, $action = "#")
 {
     if ($action != "#") {
         $tmp = $uid . "_msgs";
     } else {
         $tmp = $uid . "_alerts";
     }
     $redis = \Redis::connection('notice');
     $old = $redis->get($tmp) ? json_decode($redis->get($tmp), true) : [];
     $key = md5($text . $uid . microtime());
     $new = ['text' => $text, 'action' => $action, 'time' => date('Y-m-d H:i:s')];
     $old[$key] = $new;
     $ret = json_encode($old);
     if ($redis->set($tmp, $ret)) {
         return true;
     } else {
         return false;
     }
 }
Пример #9
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     // init
     $redis = Redis::connection();
     // get all stops
     $base_url = 'http://api.hannesv.be/';
     $endpoint = 'nmbs/stations.json';
     // perform
     $client = new Client($base_url);
     $result = $client->get($endpoint)->send()->json();
     // static
     $type = 'stop';
     $date = $this->option('date');
     $pushed = array();
     // loop
     foreach ($result['stations'] as $station) {
         // debug
         //if ($station['stop'] != 'Londerzeel') continue;
         $member = "{$type}:{$station['sid']}";
         // added to set?
         if ($redis->sismember("pulled:{$date}", $member)) {
             continue;
         }
         // add to set later
         $pushed[] = $member;
         // message
         $data = array('type' => 'stop', 'id' => (int) $station['sid'], 'date' => $date);
         // add message to queue
         Queue::push("Scraper", $data);
     }
     // pipeline
     Redis::pipeline(function ($pipe) use($pushed, $date) {
         foreach ($pushed as $member) {
             $pipe->sadd("pulled:{$date}", $member);
         }
     });
 }
Пример #10
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     // get mongodb connection
     $db = App::make('mongodb');
     $db = $db->connection()->getDb();
     // get redis connection
     $redis = Redis::connection();
     // prepare
     $this->prepare_folders();
     // get one full trip
     $trip = $this->get_one_trip($db, $this->argument('route'));
     $this->write_headers($trip);
     // loop trip
     foreach ($trip as $seq) {
         // get all nth stops
         $trips = $this->get_nth_stops($db, $this->argument('route'), $seq['sequence']);
         // loop
         foreach ($trips as $s) {
             // get static trip data
             if ($seq == reset($trip)) {
                 // allocate
                 if (!isset($hashed[$s['date']])) {
                     $hashed[$s['date']] = array();
                 }
                 if (!isset($hashed[$s['date']][$s['tid']])) {
                     $hashed[$s['date']][$s['tid']] = array();
                 }
                 // set data
                 $time = strtotime($s['date']);
                 $csv = array();
                 $csv[] = (int) date('Y', $time);
                 $csv[] = (int) date('n', $time);
                 $csv[] = (int) date('N', $time);
                 $csv[] = (int) date('j', $time);
                 $csv[] = (int) date('z', $time);
                 // allocate
                 $data = array('csv' => $csv, 'output' => array(), 'valid' => true, 'num_occupants' => 0);
             } else {
                 $data = $hashed[$s['date']][$s['tid']];
             }
             // check if db input useable for AI
             if ($seq == reset($trip) && !isset($s['departure_time']) || $seq == end($trip) && !isset($s['arrival_time']) || !isset($s['arrival_time']) && !isset($s['departure_time'])) {
                 $data['valid'] = false;
                 $hashed[$s['date']][$s['tid']] = $data;
                 continue;
             }
             // add data
             // all exept first
             if ($seq != reset($trip)) {
                 $arrival_time = strtotime($s['arrival_time']);
                 $data['csv'][] = isset($s['arrive']) ? count($s['arrive']) : 0;
                 $data['csv'][] = (int) date('G', $arrival_time) * 60 + (int) date('i', $arrival_time);
                 $data['output'][] = $s['arrival_delay'] > 0 ? 1 : 0;
             }
             // all execpt last
             if ($seq != end($trip)) {
                 $departure_time = strtotime($s['departure_time']);
                 $data['csv'][] = isset($s['depart']) ? count($s['depart']) : 0;
                 $data['csv'][] = (int) date('G', $departure_time) * 60 + (int) date('i', $departure_time);
                 $data['output'][] = $s['departure_delay'] > 0 ? 1 : 0;
             }
             // save to memory
             $hashed[$s['date']][$s['tid']] = $data;
         }
     }
     // filter values and only valids
     $csv = array();
     $csv_out = array();
     foreach ($hashed as $date => &$trips) {
         foreach ($trips as $tid => &$data) {
             if ($data['valid']) {
                 $csv[] = $data['csv'];
                 $csv_out[] = $data['output'];
             }
         }
     }
     // output
     $this->write_csv($csv);
     $this->write_csv($csv_out, true);
 }
Пример #11
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     session_start();
     if (!isset($_SESSION['AUTH']) || $_SESSION['AUTH'] == false) {
         \App::abort(500, 'User not authenticated');
     }
     $i = instanceUser::find($id);
     try {
         //emit request to make db
         $redis = \Redis::connection();
         // Using the Redis extension provided client
         $redis->publish('demeter', json_encode(array('command' => 'deleteInstanceUser', 'vm' => $i->instance->vmId, 'instanceId' => $i->instance->id, 'instanceName' => $i->instance->name, 'username' => $i->name, 'netId' => $_SESSION['AUTH_USER'])));
         if ($i->delete()) {
             echo "success";
         } else {
             \App::abort(500, 'User could not be deleted, please contact an Administrator');
         }
     } catch (Exception $e) {
         \App::abort(500, 'User could not be deleted, please contact an Administrator');
     }
 }
Пример #12
0
 public function backup()
 {
     session_start();
     if (!isset($_SESSION['AUTH']) || $_SESSION['AUTH'] == false) {
         \App::abort(500, 'User not authenticated');
     }
     $put = file_get_contents('php://input');
     $data = json_decode($put, true);
     if ($data['instanceId'] != null && $data['vmId'] != null && $data['type'] != null) {
         try {
             //emit request to make db
             $redis = \Redis::connection();
             // Using the Redis extension provided client
             $redis->publish('demeter', json_encode(array('command' => 'backupInstance', 'instanceId' => $data['instanceId'], 'vm' => $data['vmId'], 'type' => $data['type'], 'netId' => $_SESSION['AUTH_USER'])));
             print "success";
         } catch (Exception $e) {
             \App::abort(500, 'Database could not be backed up, please contact an Administrator');
         }
     } else {
         \App::abort(500, 'Database could not be backed up, did you fill all fields?');
     }
 }
Пример #13
0
<?php

Event::listen('auth.login', function ($user) {
    $redis = Redis::connection();
    // $redis->set('u'.$user->id, $user->email);
    $u = array('id' => $user->id, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'email' => $user->email);
    $redis->publish('auth.login', json_encode($u));
});
 public function handle($data)
 {
     $redis = Redis::connection();
     $redis->publish(self::CHANNEL, $data);
 }
Пример #15
0
 /**
  * add extra jobs to the queue based on scraped data
  */
 private function queue_trips($result)
 {
     // failsafe
     if (empty($result)) {
         return false;
     }
     // redis init
     $redis = Redis::connection();
     // static
     $type = 'trip';
     $first = reset($result);
     $date = $first['date'];
     // failsafe
     if (!$date) {
         return false;
     }
     // empty
     $pushed = array();
     // loop results
     foreach ($result as $trip) {
         $member = "{$type}:{$trip['tid']}";
         // added to set?
         if ($redis->sismember("pulled:{$date}", $member)) {
             continue;
         }
         // add to set later
         $pushed[] = $member;
         // message
         $data = array('type' => $type, 'id' => $trip['tid'], 'date' => $date);
         // add message to queue
         if (App::environment() == 'production') {
             Queue::push("Scraper", $data);
         }
     }
     $add = function ($pushed) use($date) {
         // pipeline
         Redis::pipeline(function ($pipe) use($pushed, $date) {
             foreach ($pushed as $member) {
                 $pipe->sadd("pulled:{$date}", $member);
             }
         });
     };
     $this->moderate($pushed, $add);
 }
Пример #16
0
 public function __construct()
 {
     $this->redis = Redis::connection();
 }
Пример #17
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     // start timer
     $start = microtime(true);
     // get all trips by day
     $hash = $this->get_trips();
     // set counter to 0
     $this->number = 0;
     // loop
     foreach ($hash as $tid => $value) {
         // min
         $min = $value[1];
         // sequence 1 → ...
         // max
         $max = $value[max(array_keys($value))];
         // string representation
         $str = isset($max['arrival_delay']) ? "- {$max['arrival_delay']} seconds" : 'now';
         // times
         $min_time = date('c');
         $max_time = date('c', strtotime($str));
         // potentially cancelled
         if (isset($min['cancelled']) && isset($max['cancelled'])) {
             // do nothing
         } elseif (isset($min['cancelled'])) {
             // only beginning part of trip is cancelled
             if ($max['arrival_time'] >= $max_time) {
                 $this->add($tid, $min['date']);
             }
         } elseif (isset($max['cancelled'])) {
             // only end part of trip is cancelled
             // get latest stop where not cancelled
             $max = $min;
             // loop
             foreach ($value as $seq => &$s) {
                 // find latest
                 if (isset($s['departure_time']) && isset($s['arrival_time']) && $s['departure_time'] >= $max['departure_time']) {
                     $max = $s;
                 }
             }
             // see if latest is after now
             $str = isset($max['arrival_delay']) ? "- {$max['arrival_delay']} seconds" : 'now';
             $max_time = date('c', strtotime($str));
             // between first and last stop
             if ($min['departure_time'] <= $min_time && $max['arrival_time'] >= $max_time) {
                 // trip is active
                 $this->add($tid, $min['date']);
             }
         } elseif (isset($min['departure_time']) && isset($max['arrival_time']) && $min['departure_time'] <= $min_time && $max['arrival_time'] >= $max_time) {
             // trip is active
             $this->add($tid, $min['date']);
         }
     }
     // save statistics if usefull
     if ($this->number) {
         // get connection
         $redis = Redis::connection();
         // save number of added jobs
         $redis->hset('stats:' . date('Ymd', strtotime('- 3 hours')), date('c'), $this->number);
     }
     // debug info
     echo "Looped all trips, found {$this->number} active.\n";
     echo "In " . (microtime(true) - $start) . " seconds.\n";
 }
 public function getProcessNotice()
 {
     $uinfo = \Session::get('adminlogin');
     $redis = \Redis::connection('notice');
     switch (\Request::input('k')) {
         case 'all_msg':
             $redis->del($uinfo->id . "_msgs");
             return redirect()->back();
             break;
         case 'all_alert':
             $redis->del($uinfo->id . "_alerts");
             return redirect()->back();
             break;
         default:
             $msgs = json_decode($redis->get($uinfo->id . "_msgs"), true);
             $content = array_get($msgs, \Request::input('k'));
             if ($content) {
                 array_forget($msgs, \Request::input('k'));
                 $redis->set($uinfo->id . "_msgs", json_encode($msgs));
             } else {
                 $alerts = json_decode($redis->get($uinfo->id . "_alerts"), true);
                 $content = array_get($alerts, \Request::input('k'));
                 array_forget($alerts, \Request::input('k'));
                 $redis->set($uinfo->id . "_alerts", json_encode($alerts));
             }
             if ($content['action'] != '#') {
                 return redirect()->action($content['action']);
             }
             return redirect()->back();
     }
 }
Пример #19
0
 /**
  * Get the Redis connection instance.
  *
  * @return \Redis
  */
 public function connection()
 {
     return $this->redis->connection($this->connection);
 }
Пример #20
0
 /**
  * Get the connection for the queue.
  *
  * @return \Redis
  */
 protected function getConnection()
 {
     return $this->redis->connection($this->connection);
 }