当前位置: 首页>>代码示例>>PHP>>正文


PHP AppCore::GetRedis方法代码示例

本文整理汇总了PHP中Railpage\AppCore::GetRedis方法的典型用法代码示例。如果您正苦于以下问题:PHP AppCore::GetRedis方法的具体用法?PHP AppCore::GetRedis怎么用?PHP AppCore::GetRedis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Railpage\AppCore的用法示例。


在下文中一共展示了AppCore::GetRedis方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getCoverImageOfObject

 /**
  * Get the cover image of the supplied object
  * @since Version 3.9.1
  * @param object $Object
  * @return array
  */
 public static function getCoverImageOfObject($Object)
 {
     if (!self::hasCoverImage($Object)) {
         return false;
     }
     $cachekey = sprintf("railpage:%s=%d;coverimage", $Object->namespace, $Object->id);
     $Memcached = AppCore::getMemcached();
     $Redis = AppCore::GetRedis();
     #printArray($cachekey);die;
     if ($result = $Memcached->fetch($cachekey)) {
         return $result;
     }
     if ($result = $Redis->fetch($cachekey)) {
         return $result;
     }
     $photoidvar = isset($Object->flickr_image_id) ? "flickr_image_id" : "photo_id";
     if (isset($Object->meta['coverimage'])) {
         $Image = ImageFactory::CreateImage($Object->meta['coverimage']['id']);
     } elseif ($Object->Asset instanceof Asset) {
         $Image = $Object->Asset;
     } elseif (isset($Object->{$photoidvar}) && filter_var($Object->{$photoidvar}, FILTER_VALIDATE_INT) && $Object->{$photoidvar} > 0) {
         $Image = ImageFactory::CreateImage($Object->{$photoidvar}, "flickr");
     }
     $return = array("type" => "image", "provider" => $Image instanceof Image ? $Image->provider : "", "title" => $Image instanceof Image ? $Image->title : $Asset->meta['title'], "author" => array("id" => "", "username" => "", "realname" => "", "url" => ""));
     if ($Image instanceof Image) {
         $return = array_merge($return, array("author" => array("id" => $Image->author->id, "username" => $Image->author->username, "realname" => isset($Image->author->realname) ? $Image->author->realname : $Image->author->username, "url" => $Image->author->url), "image" => array("id" => $Image->id), "sizes" => $Image->sizes, "url" => $Image->url->getURLs()));
     }
     if ($Object->Asset instanceof Asset) {
         $return = array_merge($return, array("sizes" => array("large" => array("source" => $Asset->meta['image']), "original" => array("source" => $Asset->meta['original'])), "url" => array("url" => $Asset['meta']['image'])));
     }
     $Memcached->save($cachekey, $return, strtotime("+1 hour"));
     $Redis->save($cachekey, $return, strtotime("+1 hour"));
     return $return;
 }
开发者ID:railpage,项目名称:railpagecore,代码行数:40,代码来源:CoverImageUtility.php

示例2: getLocationId

 /**
  * Get a location ID from a URL slug
  * @since Version 3.10.0
  * @param string $slug
  * @return int
  */
 public static function getLocationId($slug)
 {
     $Redis = AppCore::GetRedis();
     $Memcached = AppCore::GetMemcached();
     $Database = (new AppCore())->getDatabaseConnection();
     $key = sprintf("railpage:locations.slug=%s", $slug);
     if (!($id = $Memcached->fetch($key))) {
         $id = $Database->fetchOne("SELECT id FROM location WHERE slug = ?", $slug);
         $Memcached->save($key, $id, 0);
     }
     return $id;
 }
开发者ID:railpage,项目名称:railpagecore,代码行数:18,代码来源:LocationUtility.php

示例3: clearCache

 /**
  * Clear the caches of this user object
  * @since Version 3.9.1
  * @param \Railpage\Users\User $User
  * @return void
  */
 public static function clearCache(User $userObject)
 {
     if (empty($userObject->mckey)) {
         return;
     }
     $cacheHandler = AppCore::GetMemcached();
     $Redis = AppCore::GetRedis();
     $cacheHandler->delete($userObject->mckey);
     try {
         $Redis->delete(sprintf("railpage:users.user=%d", $userObject->id));
     } catch (Exception $e) {
         // throw it away
     }
     try {
         $Redis->delete($userObject->mckey);
     } catch (Exception $e) {
         // throw it away
     }
 }
开发者ID:railpage,项目名称:railpagecore,代码行数:25,代码来源:UserUtility.php

示例4: CreateImage

 /**
  * Return a new instance of Image
  * @since Version 3.9.1
  * @param int|string $id
  * @param string $provider
  * @param int $options
  * @return \Railpage\Images\Image
  */
 public static function CreateImage($id = null, $provider = null, $options = null)
 {
     $Redis = AppCore::GetRedis();
     $Registry = Registry::GetInstance();
     $cachekey = sprintf("rp:v2;cache.image=%s;o=%s", $id, crc32(json_encode($options)));
     if ($id != null && $provider == null) {
         return new Image($id, $options);
         try {
             $Image = $Registry->get($cachekey);
         } catch (Exception $e) {
             if (!($Image = $Redis->fetch($cachekey))) {
                 $Image = new Image($id, $options);
                 $Redis->save($cachekey, $Image, strtotime("+10 minutes"));
             }
             $Registry->set($cachekey, $Image);
         }
         return $Image;
     }
     $cachekey .= sprintf(";p=%s", $provider);
     #$Registry = Registry::getInstance();
     #echo $cachekey;die;
     return (new Images())->findImage($provider, $id, $options);
     try {
         $Image = $Registry->get($cachekey);
     } catch (Exception $e) {
         if ($Image = $Redis->fetch($cachekey) && $Image instanceof Image) {
             $Registry->set($cachekey, $Image);
             return $Image;
         }
         try {
             $Images = new Images();
             $Image = $Images->findImage($provider, $id, $options);
             $Redis->save($cachekey, $Image, strtotime("+10 minutes"));
             $Registry->set($cachekey, $Image);
         } catch (Exception $e) {
             $Image = false;
         }
     }
     return $Image;
 }
开发者ID:railpage,项目名称:railpagecore,代码行数:48,代码来源:ImageFactory.php

示例5: commit

 /**
  * Commit changes to this competition
  * @since Version 3.9.1
  * @return \Railpage\Images\Competition
  */
 public function commit()
 {
     $this->validate();
     $data = array("title" => $this->title, "theme" => $this->theme, "description" => $this->description, "slug" => $this->slug, "status" => $this->status, "author" => $this->Author->id, "voting_date_open" => $this->VotingDateOpen instanceof DateTime ? $this->VotingDateOpen->format("Y-m-d H:i:s") : "0000-00-00 00:00:00", "voting_date_close" => $this->VotingDateClose instanceof DateTime ? $this->VotingDateClose->format("Y-m-d H:i:s") : "0000-00-00 00:00:00", "submissions_date_open" => $this->SubmissionsDateOpen instanceof DateTime ? $this->SubmissionsDateOpen->format("Y-m-d H:i:s") : "0000-00-00 00:00:00", "submissions_date_close" => $this->SubmissionsDateClose instanceof DateTime ? $this->SubmissionsDateClose->format("Y-m-d H:i:s") : "0000-00-00 00:00:00", "meta" => json_encode($this->meta));
     if (filter_var($this->id, FILTER_VALIDATE_INT)) {
         $where = array("id = ?" => $this->id);
         $this->db->update("image_competition", $data, $where);
     }
     if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
         $this->db->insert("image_competition", $data);
         $this->id = $this->db->lastInsertId();
     }
     /**
      * Clear the cache
      */
     $regkey = sprintf(self::CACHE_KEY, $this->id);
     $Redis = AppCore::GetRedis();
     $Memcached = AppCore::GetMemcached();
     $Redis->delete($regkey);
     $Memcached->delete($regkey);
     /**
      * Check our themes and see if we need to mark this theme as used
      */
     $themes = (new Competitions())->getSuggestedThemes();
     foreach ($themes as $key => $theme) {
         $theme['theme'] = ContentUtility::FormatTitle($theme['theme']);
         if ((!isset($theme['used']) || $theme['used'] === false) && $theme['theme'] === $this->theme) {
             $themes[$key]['used'] = true;
         }
     }
     $Config = new Config();
     $Config->set("image.competition.suggestedthemes", json_encode($themes), "Photo competition themes");
     $this->url = Utility\Url::makeCompetitionUrls($this);
     return $this;
 }
开发者ID:railpage,项目名称:railpagecore,代码行数:40,代码来源:Competition.php

示例6: test_group

 /**
  * @depends test_newUser
  */
 public function test_group($User)
 {
     $User->Redis = new \Railpage\NullCacheDriver();
     $this->assertEquals(0, count($User->getGroups()));
     $Group = new Group();
     $Group->name = "Test user group";
     $Group->desc = "A test user group description";
     $Group->type = Group::TYPE_HIDDEN;
     $Group->owner_user_id = $User->id;
     $Group->commit();
     // Nuke our Redis cache
     $mckey = sprintf("railpage:group=%d.user_id=%d", $Group->id, $User->id);
     $Redis = \Railpage\AppCore::GetRedis();
     $Redis->Delete($mckey);
     $this->assertFalse(!filter_var($Group->id, FILTER_VALIDATE_INT));
     $this->assertFalse($Group->userInGroup($User));
     $Group->addMember($User->username, $User->id);
     $Group->approveUser($User);
     $this->assertTrue($Group->userInGroup($User));
     $Group->removeUser($User);
     $this->assertFalse($Group->userInGroup($User));
     $Group->addMember($User->username, $User->id, "Manager", "03 9562 2222", "blah");
     $Group->approveUser($User);
     $this->assertTrue($Group->userInGroup($User));
     $members = $Group->getMembers();
     $this->assertTrue(is_array($members));
     $this->assertTrue(count($members['members']) > 0);
     $this->assertTrue($User->inGroup($Group->id));
     $this->assertTrue(count($User->getGroups()) > 0);
     $NewGroup = new Group($Group->id);
     $this->assertEquals($NewGroup->id, $Group->id);
     $this->assertEquals($NewGroup->name, $Group->name);
     $this->assertEquals($NewGroup->desc, $Group->desc);
     $this->assertEquals($NewGroup->type, $Group->type);
     $Group->type = Group::TYPE_OPEN;
     $Group->commit();
     if (!defined("RP_GROUP_ADMINS")) {
         define("RP_GROUP_ADMINS", "michaelisawesome");
     }
     $this->assertFalse($User->inGroup());
     $this->assertFalse($User->inGroup(RP_GROUP_ADMINS));
     $User->level = 2;
     $this->assertTrue($User->inGroup(RP_GROUP_ADMINS));
     $User->level = 1;
     return $Group;
 }
开发者ID:railpage,项目名称:railpagecore,代码行数:49,代码来源:UserTest.php

示例7: commit

 /**
  * Commit changes to this camera
  * @since Version 3.10.0
  * @return \Railpage\Images\Camera
  */
 public function commit()
 {
     $this->validate();
     $data = ["make" => $this->manufacturer, "model" => $this->name, "url_slug" => $this->slug, "image" => $this->image, "text" => $this->text, "meta" => json_encode($this->meta)];
     if (filter_var($this->id, FILTER_VALIDATE_INT)) {
         $where = ["id = ?" => $this->id];
         $this->db->update("image_camera", $data, $where);
     }
     if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
         $this->db->insert("image_camera", $data);
         $this->id = $this->db->lastInsertId();
     }
     /**
      * Flush cache
      */
     $regkey = sprintf(self::CACHE_KEY, $this->id);
     $Redis = AppCore::GetRedis();
     $Memcached = AppCore::GetMemcached();
     $Redis->delete($regkey);
     $Memcached->delete($regkey);
     $this->makeURLs();
     return $this;
 }
开发者ID:railpage,项目名称:railpagecore,代码行数:28,代码来源:Camera.php


注:本文中的Railpage\AppCore::GetRedis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。