Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 public function dashboard()
 {
     $messages = Redis::lrange('messages', 0, -1);
     $messages = $messages ? $messages : [];
     $tasks = Auth::user()->tasks()->get();
     return view('dashboard', compact('messages', 'tasks'));
 }
 public function create($object_id)
 {
     $newComment = Comment::create(['object_id' => $object_id, 'user_id' => Auth::id(), 'comment' => Input::get('comment.comment'), 'parent' => Input::get('comment.parent'), 'depth' => 0]);
     $comment = Comment::where('comment_id', $newComment->comment_id)->with('user')->first();
     Redis::sadd('objects:toReindex', $object_id);
     return response()->json($comment);
 }
Ejemplo n.º 4
0
 /**
  *
  *
  */
 public function welcome()
 {
     $topic = new \App\Topic();
     $topics = $topic->recentlyCreated();
     $categories = new \App\Categories();
     $categories = $categories->all();
     //If user then check if they have confirmed email and username
     if (Auth::user()) {
         //if email is not confirm
         if (Auth::user()->confirmed == 0) {
             return redirect('/verification');
         }
         //if displayname is not set
         if (empty(Auth::user()->displayname)) {
             return redirect()->action('ProfileController@createName');
         }
     }
     $storage = Redis::connection();
     $mostView = $storage->zRevRange('postViews', 0, 1);
     foreach ($mostView as $value) {
         $id = str_replace('post:', '', $value);
         //            echo "<br> post". $id;
     }
     return view('welcome', compact('topics', 'categories'));
 }
Ejemplo n.º 5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $a = Redis::command("KEYS", ['q*']);
     foreach ($a as $cmd) {
         $q = $cmd;
         $t = Redis::command('TYPE', [$q]);
         if ($t == 'zset') {
             $count = Redis::command('ZCARD', [$q]);
         } else {
             if ($t == 'list') {
                 $count = Redis::command('LLEN', [$q]);
             } else {
                 $count = 'x';
             }
         }
         $this->info($cmd . ' ' . $t . ' ' . $count);
     }
     if (count($a)) {
         $abort = $this->option('force');
         if ($abort || $this->ask("Abort queues (y/N)?", 'N') == 'y') {
             $this->comment("Aborting...");
             foreach ($a as $cmd) {
                 Redis::command("DEL", [$cmd]);
             }
             $this->comment("Aborted");
         }
     } else {
         $this->info('Queues not found');
     }
 }
 public function checkRedis($config)
 {
     $startTime = $this->slog_time();
     $checkResult['checkType'] = 'Check Redis';
     $checkResult['checkService'] = 'Connect Redis';
     $checkResult['type'] = 'Redis';
     $checkResult['url'] = Config::get('database.redis.' . $config['redis'] . '.host');
     try {
         $redis = Redis::connection();
         $ping = $redis->ping();
         if (empty($redis)) {
             $checkResult['setStatus'] = false;
             $checkResult['setMessage'] = 'fail';
             $checkResult['setTime'] = $this->elog_time($startTime);
         } else {
             $checkResult['setStatus'] = true;
             $checkResult['setMessage'] = 'Success';
             $checkResult['setTime'] = $this->elog_time($startTime);
         }
     } catch (\Exception $e) {
         $checkResult['setStatus'] = false;
         $checkResult['setMessage'] = $e->getMessage();
         $checkResult['setTime'] = $this->elog_time($startTime);
     }
     return $checkResult;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Fetch objects and delete redis sets
     $objects = Object::whereIn('object_id', Redis::smembers('objects:toReindex'))->get();
     $collections = Collection::whereIn('collection_id', Redis::smembers('collections:toReindex'))->get();
     $dataViews = DataView::whereIn('dataview_id', Redis::smembers('dataviews:toReindex'))->get();
     Redis::del(['objects:toReindex', 'collections:toReindex', 'dataviews:toReindex']);
     // Map to return searchable interfaces and reindex
     if ($objects->count() > 0) {
         foreach ($objects as $object) {
             $searchableObjects[] = $object->search();
         }
         Search::bulkReindex($searchableObjects);
     }
     if ($collections->count() > 0) {
         foreach ($collections as $collection) {
             $searchableCollections[] = $collection->search();
         }
         Search::bulkReindex($searchableCollections);
     }
     if ($dataViews->count() > 0) {
         foreach ($dataViews as $dataView) {
             $searchableDataViews[] = $dataView->search();
         }
         Search::bulkReindex($searchableDataViews);
     }
 }
 private function registerCache()
 {
     $this->app->singleton(Cache::class, function ($app) {
         $config = $this->laravelToDoctrineConfigMapper();
         $cacheClass = "\\Doctrine\\Common\\Cache\\" . $config['type'];
         if (!class_exists($cacheClass)) {
             throw new Exception\ImplementationNotFound($cacheClass);
         }
         switch ($config['type']) {
             case 'ArrayCache':
                 $cache = new $cacheClass();
                 break;
             case 'FilesystemCache':
                 $cache = new $cacheClass($config['dir']);
                 break;
             case 'MemcacheCache':
                 $cache = new $cacheClass();
                 $cache->setMemcache($this->setupMemcache($config));
                 break;
             case "PredisCache":
                 $cache = new $cacheClass(Redis::connection($config['connection']));
                 break;
         }
         if (Config::has('d2bcache.namespace')) {
             $cache->setNamespace(Config::get('d2bcache.namespace'));
         }
         return $cache;
     });
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $youtube = new Client();
     $searchResponse = json_decode($youtube->get('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' . $this->channelID . '&eventType=live&type=video&key=' . Config::get('services.youtube.key'))->getBody());
     $isLive = $searchResponse->pageInfo->totalResults != 0;
     // Determine the total number of viewers
     if ($isLive) {
         $videoResponse = json_decode($youtube->get('https://www.googleapis.com/youtube/v3/videos?part=liveStreamingDetails&id=' . $searchResponse->items[0]->id->videoId . '&key=' . Config::get('services.youtube.key'))->getBody());
         $viewers = $videoResponse->items[0]->liveStreamingDetails->concurrentViewers;
     } else {
         $viewers = 0;
     }
     // If the livestream is active now, and wasn't before, or vice versa, send an event
     if ($isLive && (Redis::hget('webcast', 'isLive') == 'false' || !Redis::hexists('webcast', 'isLive'))) {
         // Grab all the relevant SpaceX youtube Livestreams, and create an event
         $videos = $this->getMultipleYoutubeLivestreams($videoId);
         // $searchResponse->items[0]->id->videoId
         event(new WebcastStartedEvent($videos));
     } elseif (!$isLive && Redis::hget('webcast', 'isLive') == 'true') {
         // turn off the spacex webcast
         event(new WebcastEndedEvent("spacex", false));
     }
     // Set the Redis properties
     Redis::hmset('webcast', 'isLive', $isLive === true ? 'true' : 'false', 'viewers', $viewers);
     // Add to Database if livestream is active
     if ($isLive) {
         WebcastStatus::create(['viewers' => $viewers]);
     }
 }
Ejemplo n.º 10
0
 public function __construct()
 {
     $this->redis = Redis::connection();
     if (!$this->redis) {
         throw new \Exception("redis connection error", 80000);
     }
 }
Ejemplo n.º 11
0
 public function end()
 {
     if ($this->qid) {
         $queueJob = QueueJob::get($this->qid);
         $queueJob = $queueJob->finish();
         Redis::LSET(config('queue-managers.name'), $queueJob->qid, $queueJob->toJson());
     }
 }
Ejemplo n.º 12
0
  public function __construct($arrInfo)
  {
    $this->arr = $arrInfo;
    // $this->redis = new Redis();
    $this->redis = Redis::connection('default');
    // $this->redis->connect('127.0.0.1',6379);

  }
Ejemplo n.º 13
0
 public function setDescription()
 {
     //Redisアクセス
     $redisData = Redis::connection();
     $setData[] = array('parking_space_id' => '1', 'description_id' => '1', 'description_type' => '3', 'title_text' => '夜はお静かに');
     $setJsonData = json_encode($setData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
     //$redisData->delete('00000001');
     $redisData->hSet('parking_description_1', '1', $setJsonData);
 }
Ejemplo n.º 14
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($motto)
 {
     $result = Redis::command('SREM', ['mottos', $motto]);
     if ($result) {
         return redirect('/admin/motto')->with('message', '删除博客签名成功.');
     } else {
         return redirect('/admin/motto')->with('message', '添加博客签名失败.');
     }
 }
Ejemplo n.º 15
0
 public function issue($type, UserModel $destinationUser, ProjectModel $projectModel, ActivityModel $activityModel, $corpus)
 {
     $notification = NotificationModel::generate($type, $destinationUser, $projectModel, $activityModel, $corpus);
     $not = $this->notificationRepository->save($notification);
     $redis = Redis::connection();
     $transformer = \App::make(NotificationTransformer::class);
     $redis->publish($destinationUser->hash, json_encode($transformer->transform($notification)));
     return $not;
 }
Ejemplo n.º 16
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->infoStart('Getting official skin list...');
     $skins = $this->getOfficialSkinList();
     $this->infoFinish('Getting official skin done');
     $this->infoStart('Resolving skin ids to items...');
     $skins = $this->resolveSkinsToItems($skins);
     $this->infoFinish('Resolving skin ids to items done');
     Redis::set(self::$key, serialize($skins));
 }
Ejemplo n.º 17
0
 public function sendMessage(Request $request)
 {
     try {
         $redis = Redis::connection();
         $redis->publish('message', $request->get('message'));
         return redirect('writemessage');
     } catch (Exception $exc) {
         echo $exc->getTraceAsString();
     }
 }
Ejemplo n.º 18
0
 /**
  * Send the response after the user was authenticated.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  bool  $throttles
  * @return \Illuminate\Http\Response
  */
 protected function handleUserWasAuthenticated(Request $request, $throttles)
 {
     if ($throttles) {
         $this->clearLoginAttempts($request);
     }
     if (method_exists($this, 'authenticated')) {
         return $this->authenticated($request, Auth::user());
     }
     Redis::publish('connected', Auth::user());
     return redirect()->intended($this->redirectPath());
 }
 /**
  * Extend broadcast manager
  */
 public function boot()
 {
     //publish
     $this->publishes([sprintf('%1$s%2$s..%2$s%3$s%2$s%3$s.php', __DIR__, DIRECTORY_SEPARATOR, Constants\Common::TAG_CONFIG) => base_path(sprintf('%s%s%s.php', Constants\Common::TAG_CONFIG, DIRECTORY_SEPARATOR, Constants\Common::T_NAMESPACE))], Constants\Common::TAG_CONFIG);
     //extend broadcast manager
     app(BroadcastManager::class)->extend('socket.io', function ($app) {
         $config = $app['config'];
         //init socket.io broadcaster
         return new SocketIOBroadcaster(new Emitter(Redis::connection($config->get('broadcasting.connections.socket\\.io.redis.connection', 'default')), $config->get(sprintf('%s.emitter.prefix', Constants\Common::T_NAMESPACE), Constants\Common::EMITTER_PREFIX)));
     });
 }
Ejemplo n.º 20
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->infoStart('Parsing EU leaderboard...');
     $eu_rankings = $this->parseLeaderboard('eu');
     $this->infoFinish('Done parsing!');
     $this->infoStart('Parsing NA leaderboard...');
     $na_rankings = $this->parseLeaderboard('na');
     $this->infoFinish('Done parsing!');
     Redis::set(self::$key, serialize(['eu' => $eu_rankings, 'na' => $na_rankings]));
     // Trigger an event for post-processor to hook into
     Event::fire(new PvpLeaderboardUpdated());
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // Rerender content
     $templatedOutput = view('templates.livethreadcontents')->with(['updates' => collect(Redis::lrange('live:updates', 0, -1))->reverse()->map(function ($update) {
         return json_decode($update);
     })])->render();
     // Connect to Reddit
     $reddit = new Reddit(Config::get('services.reddit.username'), Config::get('services.reddit.password'), Config::get('services.reddit.id'), Config::get('services.reddit.secret'));
     $reddit->setUserAgent('ElongatedMuskrat bot by u/EchoLogic. Runs various /r/SpaceX-related tasks.');
     // Update Thread
     $reddit->thing(Redis::hget('live:reddit', 'thing'))->edit($templatedOutput);
 }
Ejemplo n.º 22
0
 /**
  * @param int $start
  * @param int $end
  * @param string $view
  *
  * @return \Illuminate\View\View
  */
 protected function linkView($start, $end, $view)
 {
     $links = [];
     for ($i = $start; $i <= $end; $i += 1) {
         $hash = 'link:' . $i;
         $title = Redis::command('hget', [$hash, 'title']);
         if ($title !== null) {
             $links[$i] = $title;
         }
     }
     return view($view, ['links' => $links]);
 }
Ejemplo n.º 23
0
 private function clear_articels_cache()
 {
     $pages = Redis::command('lrange', ['welcome:articles:pages', 0, -1]);
     foreach ($pages as $cache_key) {
         if (Cache::has($cache_key)) {
             Cache::forget($cache_key);
         }
     }
     Redis::command('del', ['welcome:articles:pages']);
     Cache::forget('self:rss');
     Cache::forget('self:archive');
     Cache::forget('self::categorie');
 }
 public function getStatus()
 {
     // Check if the redis values exist
     try {
         //if (Redis::exists('webcast:isLive') == 1 && Redis::exists('webcast:viewers') == 1) {
         return response()->json(Redis::hgetall('webcast'));
         //} else {
         //	return response()->json(array('isLive' => null, 'viewers' => null));
         //}
     } catch (Predis\Connection\ConnectionException $e) {
         return response()->json(['isLive' => null, 'viewers' => null]);
     }
 }
Ejemplo n.º 25
0
 public function authenticate(Request $request)
 {
     \R::setup('mysql:host=localhost;dbname=gazingle', 'root', '');
     $redis = Redis::connection();
     $user = \R::getRow('select * from users where email = "' . $request->email . '"');
     //return $user;
     if ($request->password === \Crypt::decrypt($user['password'])) {
         \Auth::loginUsingId($user['id']);
         $redis->set(\Crypt::encrypt($request->email), $user['id']);
         return $redis->get($request->email);
     }
     return response('Unauthorized.', 401);
 }
Ejemplo n.º 26
0
 /**
  * Constructs a human readable relative timestamp relative to when the event is being counted down to.
  * If a launch is paused, we will instead show a timestamp which reads "Paused".
  *
  * @internal
  * @return string
  */
 private function constructTimestamp()
 {
     // Check if paused
     if (!Redis::hget('live:countdown', 'isPaused')) {
         $countdownTo = Carbon::createFromFormat('Y-m-d H:i:s', Redis::hget('live:countdown', 'to'));
         $diffInSeconds = $this->createdAt->diffInSeconds($countdownTo, false);
         $absDiffInSeconds = abs($diffInSeconds);
         $sign = $diffInSeconds < 0 ? '+' : '-';
         if ($absDiffInSeconds > 86400) {
             $days = floor($absDiffInSeconds / 86400);
             $hours = intval(round($absDiffInSeconds % 86400 / 3600));
             $timestamp = "T{$sign}{$days}d";
             if ($hours !== 0) {
                 if ($hours === 60) {
                     $days++;
                     $timestamp = "T{$sign}{$days}d";
                 } else {
                     $timestamp .= " {$hours}h";
                 }
             }
         } elseif ($absDiffInSeconds > 3600) {
             $hours = floor($absDiffInSeconds / 3600);
             $minutes = intval(round($absDiffInSeconds % 3600 / 60));
             $timestamp = "T{$sign}{$hours}h";
             if ($minutes !== 0) {
                 if ($minutes === 60) {
                     $hours++;
                     $timestamp = "T{$sign}{$hours}d";
                 } else {
                     $timestamp .= " {$minutes}m";
                 }
             }
         } elseif ($absDiffInSeconds > 60) {
             $minutes = floor($absDiffInSeconds / 60);
             $seconds = intval(round($absDiffInSeconds % 60));
             $timestamp = "T{$sign}{$minutes}m";
             if ($seconds !== 0) {
                 if ($seconds === 60) {
                     $minutes++;
                     $timestamp = "T{$sign}{$minutes}m";
                 } else {
                     $timestamp .= " {$seconds}s";
                 }
             }
         } else {
             $timestamp = "T{$sign}{$absDiffInSeconds}s";
         }
         return $timestamp;
     }
     return 'Paused';
 }
Ejemplo n.º 27
0
 public static function boot()
 {
     parent::boot();
     Project::updating(function ($project) {
         $msg = "<a href='/projects/{$project->id}'>The project: {$project->name} was updated.</a>";
         Redis::lpush('messages', $msg);
         Redis::publish('new-message', $msg);
     });
     Project::creating(function ($project) {
         $msg = "<a href='/projects/{$project->id}'>The project: {$project->name} was created.</a>";
         Redis::lpush('messages', $msg);
         Redis::publish('new-message', $msg);
     });
 }
Ejemplo n.º 28
0
 /**
  * Function remove all redis data for specified language
  *
  * @param $language
  */
 public function clear($language)
 {
     if (Redis::del(Key::posts($language))) {
         $this->info('Remove all entries for key ' . Key::posts($language));
     }
     if (Redis::del(Key::tags($language))) {
         $this->info('Remove all entries for key ' . Key::tags($language));
     }
     foreach (Redis::keys(Key::post('*', $language)) as $key) {
         if (Redis::del($key)) {
             $this->info('Remove all entries for keys ' . $key);
         }
     }
 }
Ejemplo n.º 29
0
 public function byTag($tag)
 {
     $posts = Redis::smembers(Key::tags($tag));
     foreach ($posts as &$post) {
         $post = $this->loader->load($post);
     }
     uasort($posts, function ($a, $b) {
         return $a['published'] > $b['published'] ? -1 : 1;
     });
     $total = count($posts);
     $amount = config('blog.posts_on_page');
     $current = Request::get('page') ?: 1;
     $start = $amount * $current - $amount;
     return (new LengthAwarePaginator(array_slice($posts, $start, $amount), $total, $amount, $current))->setPath($tag);
 }
 /**
  * Create a new event instance.
  *
  * @param $isActive
  * @param null $videoId
  */
 public function __construct($videos)
 {
     foreach ($videos as $videoName => $videoId) {
         // Update the Redis parameters
         $spacexLivestream = json_decode(Redis::hget('live:streams', $videoName));
         if ($spacexLivestream === null) {
             $spacexLivestream = new \stdClass();
         }
         $spacexLivestream->isActive = true;
         $spacexLivestream->isAvailable = true;
         $spacexLivestream->youtubeVideoId = $videoId;
         Redis::hset('live:streams', $videoName, json_encode($spacexLivestream));
     }
     $this->videos = $videos;
 }