本文整理汇总了PHP中Redis::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::connection方法的具体用法?PHP Redis::connection怎么用?PHP Redis::connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
function __construct(redisModel $subject, $objectName, $index)
{
$this->redis = Redis::connection();
$this->subject = $subject;
$this->objectName = $objectName;
$this->objectIndex = $index;
}
示例2: __construct
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: cities
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: index
/**
* 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);
}
示例5: getDisableKey
/**
* 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);
}
});
}
}
示例6: boot
/**
* 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: handle
/**
* 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: notice
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: fire
/**
* 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: fire
/**
* 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: destroy
/**
* 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: backup
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: function
<?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));
});
示例14: handle
public function handle($data)
{
$redis = Redis::connection();
$redis->publish(self::CHANNEL, $data);
}
示例15: queue_trips
/**
* 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);
}