コード例 #1
0
ファイル: PredisDriver.php プロジェクト: savritsky/cache
 /**
  * @inheritdoc
  */
 public function set($key, $value, $ttl = 0)
 {
     if ($ttl > 0) {
         return $this->predis->setex($key, $ttl, $value);
     }
     return $this->predis->set($key, $value);
 }
コード例 #2
0
 /**
  * {@inheritDoc}
  */
 public function write($sessionId, $data)
 {
     if (0 < $this->ttl) {
         $this->redis->setex($this->getRedisKey($sessionId), $this->ttl, $data);
     } else {
         $this->redis->set($this->getRedisKey($sessionId), $data);
     }
 }
コード例 #3
0
ファイル: WsseTokenManager.php プロジェクト: bzis/zomba
 /**
  * @param int $userId
  *
  * @return string
  */
 public function createUserToken($userId)
 {
     $generator = new SecureRandom();
     $rand = $generator->nextBytes(12);
     $wsseToken = sha1($rand);
     $this->redis->setex(self::PREFIX . ':' . $userId, $this->ttl, $wsseToken);
     return $wsseToken;
 }
コード例 #4
0
ファイル: Redis.php プロジェクト: noikiy/Laravel.Smarty
 /**
  * Save values for a set of keys to cache
  *
  * @param  array $keys list of values to save
  * @param  int   $expire expiration time
  *
  * @return boolean true on success, false on failure
  */
 protected function write(array $keys, $expire = 1)
 {
     foreach ($keys as $k => $v) {
         $k = sha1($k);
         $this->redis->setex($k, $expire, $v);
     }
     return true;
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 protected function doSave($id, $data, $lifeTime = 0)
 {
     if ($lifeTime > 0) {
         $response = $this->client->setex($id, $lifeTime, $data);
     } else {
         $response = $this->client->set($id, $data);
     }
     return $response === true || $response == 'OK';
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 protected function doSave($id, $data, $lifeTime = false)
 {
     if (0 < $lifeTime) {
         $result = $this->redis->setex($id, (int) $lifeTime, serialize($data));
     } else {
         $result = $this->redis->set($id, serialize($data));
     }
     return (bool) $result;
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function save($id, $data, $lifeTime = 0)
 {
     if ($lifeTime > 0) {
         $response = $this->client->setex($this->prefix . $id, $lifeTime, $data);
     } else {
         $response = $this->client->set($this->prefix . $id, $data);
     }
     return $response === true || $response == 'OK';
 }
コード例 #8
0
ファイル: Predis.php プロジェクト: molovo/amnesia
 /**
  * Set a value against a key in the cache.
  *
  * @param string   $key     The key to store against
  * @param string   $value   A json_encoded value
  * @param int|null $expires Optional expiry time in seconds from now
  */
 public function set($key, $value = null, $expires = null)
 {
     if ($value === null) {
         return $this->clear($key);
     }
     if ($expires === null) {
         return $this->client->set($key, $value);
     }
     return $this->client->setex($key, $expires, $value);
 }
コード例 #9
0
ファイル: Redis.php プロジェクト: tomwright/oopz
 /**
  * Persist an error.
  * @param Error $error
  * @param Handler $handler
  * @return mixed
  */
 public function persist(Error $error, Handler $handler)
 {
     $errorKey = $this->generateRedisKey($error);
     $json = $error->toJson();
     if (is_int($this->ttl)) {
         $this->predisClient->setex($errorKey, $this->ttl, $json);
     } else {
         $this->predisClient->set($errorKey, $json);
     }
     $countKey = $this->generateRedisKey($error, 'count');
     $this->predisClient->incr($countKey);
 }
コード例 #10
0
 /**
  * {@inheritdoc}
  */
 public function save($id, $data, $lifeTime = 0)
 {
     $id = $this->_getNamespacedId($id);
     $data = serialize($data);
     if ($this->_supportsSetExpire && 0 < $lifeTime) {
         $result = $this->_redis->setex($id, (int) $lifeTime, $data);
     } else {
         $result = $this->_redis->set($id, $data);
         if ($result && 0 < $lifeTime) {
             $result = $this->_redis->expire($id, (int) $lifeTime);
         }
     }
     return (bool) $result;
 }
コード例 #11
0
ファイル: WsseProvider.php プロジェクト: bzis/zomba
 /**
  * @param string $digest
  * @param string $nonce
  * @param string $created
  * @param string $secret
  *
  * @return bool
  * @throws \Symfony\Component\Security\Core\Exception\NonceExpiredException
  */
 protected function validateDigest($digest, $nonce, $created, $secret)
 {
     /*
      * закомментили 7.01.2014 из-за проблемы возможного расхождения с клиентским временем
      *
     // Check created time is not in the future
     if (strtotime($created) > time()) {
         return false;
     }
     
     // Expire timestamp after 5 minutes
     if (time() - strtotime($created) > self::TTL) {
         return false;
     }
     */
     // Validate nonce is unique within 5 minutes
     if ($this->redis->exists(self::PREFIX . ':' . $nonce)) {
         if (null !== $this->logger) {
             $this->logger->debug(sprintf('Previously used nonce detected: %s', base64_decode($nonce)));
         }
         throw new NonceExpiredException('Previously used nonce detected');
     }
     $this->redis->setex(self::PREFIX . ':' . $nonce, self::TTL, time());
     // Validate Secret
     $expected = base64_encode(sha1(base64_decode($nonce) . $created . $secret, true));
     if (null !== $this->logger) {
         $this->logger->debug(sprintf('[+] %s, [=] %s (created: %s, nonce: %s, secret: %s)', $digest, $expected, $created, base64_decode($nonce), $secret));
     }
     return $digest === $expected;
 }
コード例 #12
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //$a = new ArticleRepository(new \App\Article);
     //var_dump($a->getLatestArticles());exit();
     // 一页多少文章
     $pageNum = 10;
     $userInfo = \Auth::user();
     $data = array();
     $data['articles'] = Article::latest()->published()->get();
     $data['userInfo'] = $userInfo;
     $dataArticles = array();
     $curPage = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
     $cacheKey = 'laravel:articles:index:page:' . $curPage;
     $redis = new \Predis\Client(array('host' => '127.0.0.1', 'port' => 6379));
     $dataArticles = $redis->get($cacheKey);
     if (!$dataArticles) {
         //$dataArticles = \App\Article::latest()->take($pageNum)->with('content')->get()->toArray();
         $dataArticles = App\Article::latest()->with('content')->paginate($pageNum)->toArray();
         //var_dump($dataArticles);exit();
         $redis->setex($cacheKey, 3600 * 12, serialize($dataArticles));
     } else {
         $dataArticles = unserialize($dataArticles);
     }
     $data['articles'] = $dataArticles;
     //var_dump($data);exit();
     // $articleArr[0]['relations']['content']['content']
     return view('articles.index')->with('data', $data);
 }
コード例 #13
0
 /**
  * Appends data to an existing item on the Redis server.
  *
  * @param  string $key
  * @param  string $value
  * @param  int    $expiration
  * @return bool
  */
 protected function appendValue($key, $value, $expiration = 0)
 {
     if ($this->redis->exists($key)) {
         $this->redis->append($key, $value);
         return $this->redis->expire($key, $expiration);
     }
     return $this->redis->setex($key, $expiration, $value);
 }
コード例 #14
0
 /**
  * @param string $sessionId
  * @param string $sessionData
  *
  * @return bool
  */
 public function write($sessionId, $sessionData)
 {
     $key = $this->keyPrefix . $sessionId;
     if (strlen($sessionData) < 1) {
         return true;
     }
     $startTime = microtime(true);
     $result = $this->connection->setex($key, $this->lifetime, json_encode($sessionData));
     $this->newRelicApi->addCustomMetric(self::METRIC_SESSION_WRITE_TIME, microtime(true) - $startTime);
     return $result ? true : false;
 }
コード例 #15
0
 /**
  * Store association until its expiration time in Redis server. 
  * Overwrites any existing association with same server_url and 
  * handle. Handles list of associations for every server. 
  */
 function storeAssociation($server_url, $association)
 {
     // create Redis keys for association itself
     // and list of associations for this server
     $associationKey = $this->associationKey($server_url, $association->handle);
     $serverKey = $this->associationServerKey($server_url);
     // save association to server's associations' keys list
     $this->redis->lpush($serverKey, $associationKey);
     // Will touch the association list expiration, to avoid filling up
     $newExpiration = $association->issued + $association->lifetime;
     $expirationKey = $serverKey . '_expires_at';
     $expiration = $this->redis->get($expirationKey);
     if (!$expiration || $newExpiration > $expiration) {
         $this->redis->set($expirationKey, $newExpiration);
         $this->redis->expireat($serverKey, $newExpiration);
         $this->redis->expireat($expirationKey, $newExpiration);
     }
     // save association itself, will automatically expire
     $this->redis->setex($associationKey, $newExpiration - time(), serialize($association));
 }
コード例 #16
0
ファイル: GoogleProvider.php プロジェクト: Doanlmit/pickleweb
 /**
  * @param Application $app
  *
  * @return string token
  */
 public function handleAuth(Application $app)
 {
     $code = $app->request()->get('code');
     $state = $app->request()->get('state');
     $key = sprintf('google.oauth2state.%s', session_id());
     $sessionState = $this->redisClient->get($key);
     if (is_null($code)) {
         // If we don't have an authorization code then get one
         $url = $this->oauth2Provider->getAuthorizationUrl();
         $this->redisClient->setex($key, 300, $this->oauth2Provider->state);
         $app->redirect($url);
     } elseif (empty($state) || isset($sessionState) && $state !== $sessionState) {
         // Check given state against previously stored one to mitigate CSRF attack
         $this->redisClient->del($key);
         throw new \RuntimeException('Invalid state');
     }
     // clean session
     $this->redisClient->del($key);
     // Try to get an access token (using the authorization code grant)
     return $this->oauth2Provider->getAccessToken('authorization_code', ['code' => $code])->accessToken;
 }
コード例 #17
0
ファイル: Predis.php プロジェクト: sergeym/Stash
 /**
  * {@inheritdoc}
  */
 public function storeData($key, $data, $expiration)
 {
     $store = serialize(array('data' => $data, 'expiration' => $expiration));
     if (is_null($expiration)) {
         return $this->redis->set($this->makeKeyString($key), $store);
     }
     $ttl = $expiration - time();
     // Prevent us from even passing a negative ttl'd item to redis,
     // since it will just round up to zero and cache forever.
     if ($ttl < 1) {
         return true;
     }
     $response = $this->redis->setex($this->makeKeyString($key), $ttl, $store);
     return $response == 'OK' || $response == 'QUEUED';
 }
コード例 #18
0
 /**
  * @param Application $app
  *
  * @return string token
  */
 public function handleAuth(Application $app)
 {
     $oauthToken = $app->request()->get('oauth_token');
     $oauthVerifier = $app->request()->get('oauth_verifier');
     $key = sprintf('bitbucket.oauthCredential.%s', session_id());
     $temporaryCredential = $this->redisClient->get($key);
     if (!empty($temporaryCredential)) {
         $temporaryCredential = unserialize($temporaryCredential);
     }
     if (empty($temporaryCredential)) {
         // If we don't have an authorization code then get one
         $temporaryCredential = $this->oauthProvider->getTemporaryCredentials();
         $this->redisClient->setex($key, 300, serialize($temporaryCredential));
         $app->redirect($this->oauthProvider->getAuthorizationUrl($temporaryCredential));
     } elseif (empty($oauthVerifier) || empty($oauthToken)) {
         // Check callback
         $this->redisClient->del($key);
         throw new \RuntimeException('Invalid state');
     }
     // clean session
     $this->redisClient->del($key);
     $tokenCredentials = $this->oauthProvider->getTokenCredentials($temporaryCredential, $oauthToken, $oauthVerifier);
     return $tokenCredentials->getIdentifier() . '@' . $tokenCredentials->getSecret();
 }
コード例 #19
0
ファイル: Redis.php プロジェクト: dancannon/php-wowapi
 public function write($key, $data)
 {
     $this->redis->setex($key, $this->options->get('ttl', 3600), $data);
 }
コード例 #20
0
 /**
  * {@inheritDoc}
  */
 public function write($sessionId, $data)
 {
     $key = $this->getKey($sessionId);
     return $this->client->setex($key, $this->lifetime, $data);
 }
コード例 #21
0
 /**
  * set expired
  *
  * @param $key
  * @param $value
  * @param $ttl
  *
  * @return int
  */
 public function setExpired($key, $value, $ttl)
 {
     return $this->client->setex($key, $ttl, $value);
 }
コード例 #22
0
 /**
  * ### Sets or replaces the given key/value pair
  *
  * @param string $key
  * @param mixed $value
  * @param int $expire
  * @return bool
  */
 public function set($key, $value, $expire = 60)
 {
     $prefix = Config::get('cache', 'key_prefix');
     $this->conn->setex($prefix . $key, $expire * 60, serialize($value));
     return true;
 }
コード例 #23
0
 /**
  * Inserts an item in the cache.
  *
  * @param string $key
  * @param mixed $value
  * @param int $minutes
  *
  * @return mixed
  */
 public function set(string $key, $value, int $minutes)
 {
     $value = is_numeric($value) ? $value : serialize($value);
     $this->predis->setex($this->prefix . $key, 60 * $minutes, $value);
 }