public function retrieve($user) { $data = json_decode($this->storage->get('usr.' . $user->getKey() . '.lastSeen')); // Make the stored date into Carbon object if ($data) { $data->date = Carbon::createFromFormat('Y-m-d H:i:s', $data->date); return $data; } $data = json_decode('{"date":""}'); $data->date = Carbon::now(); return $data; }
public static function get($num = 1) { $cache_key = self::getCacheKey(); self::setCache(); $ads = unserialize(Redis::get($cache_key)); if ($num === 0) { return $ads; } $list = []; $j = 0; if (!empty($ads)) { $idx = array_rand($ads, $num); if (is_array($idx)) { foreach ($idx as $i) { $list[$j] = $ads[$i]; $j++; } } else { $list[$j] = $ads[$idx]; } } if ($num == 1) { return $list[0]; } else { return $list; } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($url) { if ($jsonString = Redis::get(env('CACHE_PREFIX') . $url)) { return response()->json($jsonString); } else { return response()->json([], 404); } }
private static function getCache($cacheKey, $startTime) { if ($cache = Redis::get($cacheKey)) { if ($response = json_decode($cache)) { $response->cached = true; $response->status = 'ok'; list($sec, $usec) = explode('.', $startTime); $response->timestamp = date('H:i:s:', $sec) . substr($usec, 0, 2); $response->time = microtime(true) - $startTime; return $response; } else { Redis::setex($cacheKey, 1, ''); return null; } } }
/** * Check for expired cache timestamp * * @param string $cached_at * @return bool */ public function check($cached_at) { $timestamp = Timestamp::get('registry_updated_at'); return $timestamp && $timestamp > $cached_at; }
/** * @return mixed */ public function resumeCountdown() { // Parse launch date $newLaunchDate = Carbon::parse(Input::get('newLaunchDate')); // Update Redis Redis::hset('live:countdown', 'isPaused', false); Redis::hset('live:countdown', 'to', $newLaunchDate->toDateTimeString()); // Event event(new LiveCountdownEvent(true, $newLaunchDate)); // If it relates to a mission (and not a miscellaneous webcast) if (Redis::get('live:isForLaunch')) { $nextMission = Mission::future()->first(); // Create a Prelaunch event PrelaunchEvent::create(['mission_id' => $nextMission->mission_id, 'event' => 'Launch Change', 'occurred_at' => Carbon::now(), 'scheduled_launch_exact' => $newLaunchDate]); // Update mission $nextMission->launch_paused = false; $nextMission->launch_date_time = $newLaunchDate; $nextMission->save(); } return response()->json(null, 204); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function test() { $data = ['name' => 'Dimas']; Redis::publish('chat-channel', json_encode($data)); return Redis::get('name'); }
<?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ use Illuminate\Support\Facades\Redis; Route::get('/', function () { return Redis::get('name'); // return view('welcome'); }); //socket.io & redis Route::resource('socket', 'SocketController'); //邮件异步发送 Route::get('/mail', ['uses' => 'MailController@index', 'as' => 'mail.index']); //api开发 Route::group(['prefix' => 'api/v1'], function () { Route::resource('lesson', 'LessonController'); }); //vuejs demo Route::resource('vue', 'VueController'); //多对多 demo Route::resource('article', 'ArticleController'); //ajax demo Vue resource Route::resource('todo', 'TodoController');
public function tidyUp() { $redisKey = config('rediskeys.digitalocean_token') . $this->provision->uuid; $sshKeys = new \App\Fodor\Ssh\Keys($this->provision->uuid); $adapter = new GuzzleHttpAdapter(Redis::get($redisKey)); $digitalocean = new DigitalOceanV2($adapter); // ## REMOVE SSH KEYS FROM DIGITALOCEAN AND OUR LOCAL FILESYSTEM ## $keysFromDo = $digitalocean->key()->getAll(); if (!empty($keysFromDo)) { foreach ($keysFromDo as $key) { if ($key->name == 'fodor-' . $this->provision->uuid) { $digitalocean->key()->delete($key->id); // Remove our fodor SSH key from the users DigitalOcean account $this->log->addInfo("Removed SSH key: {$key->name}: {$key->id} from DigitalOcean"); } } } if (\Storage::exists($sshKeys->getPublicKeyPath())) { try { $this->log->addInfo("Removed local SSH Keys"); $sshKeys->remove(); // uuid is the name of the file } catch (Exception $e) { // TODO: Handle. We should probably be alerted as we don't want these lying around } } Redis::del($redisKey); $this->provision->dateready = (new \DateTime('now', new \DateTimeZone('UTC')))->format('c'); $this->provision->exitcode = $this->exitCode; $this->provision->status = $this->exitCode === 0 ? 'ready' : 'errored'; //TODO: Other distros or shells? $this->provision->save(); //TODO: If it errored, an alert should be sent out for investigation $this->log->addInfo("Set provision row's status to {$this->provision->status}, we're done here"); }
public static function getConnection() { return Redis::get('mysql_current_connection'); }
public function redisGet() { echo Redis::get('name'); }
/** * Converts the LiveUpdate object into an array, for storage into a database, etc. * * @return array */ public function toArray() { return ['update' => $this->update, 'update_type' => $this->updateType, 'live_event_name' => Redis::get('live:title'), 'user_id' => Auth::id(), 'timestamp' => $this->timestamp, 'created_at' => $this->createdAt, 'updated_at' => $this->updatedAt]; }