Skip to content

Commit

Permalink
merged branch pulzarraider/redis_const_profiler_fix (PR #4164)
Browse files Browse the repository at this point in the history
Commits
-------

991474b [HttpKernel] RedisProfilerStorage - Fix falling unit tests when Redis extension is not available

Discussion
----------

[HttpKernel] RedisProfilerStorage - Fix falling unit tests when Redis extension is not available

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

Fix error of my PR #4150

Unit tests were falling if Redis extension was not available. It was caused by using Redis constants.
  • Loading branch information
fabpot committed Apr 30, 2012
2 parents 6f00846 + 37c6db9 commit 00d43c6
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/Symfony/Component/HttpKernel/Profiler/RedisProfilerStorage.php
Expand Up @@ -22,6 +22,11 @@ class RedisProfilerStorage implements ProfilerStorageInterface
{
const TOKEN_PREFIX = 'sf_profiler_';

const REDIS_OPT_SERIALIZER = 1;
const REDIS_OPT_PREFIX = 2;
const REDIS_SERIALIZER_NONE = 0;
const REDIS_SERIALIZER_PHP = 1;

protected $dsn;
protected $lifetime;

Expand Down Expand Up @@ -51,7 +56,7 @@ public function find($ip, $url, $limit, $method)
{
$indexName = $this->getIndexName();

if (!$indexContent = $this->getValue($indexName, Redis::SERIALIZER_NONE)) {
if (!$indexContent = $this->getValue($indexName, self::REDIS_SERIALIZER_NONE)) {
return array();
}

Expand Down Expand Up @@ -103,7 +108,7 @@ public function purge()
// delete only items from index
$indexName = $this->getIndexName();

$indexContent = $this->getValue($indexName, Redis::SERIALIZER_NONE);
$indexContent = $this->getValue($indexName, self::REDIS_SERIALIZER_NONE);

if (!$indexContent) {
return false;
Expand Down Expand Up @@ -137,7 +142,7 @@ public function read($token)
return false;
}

$profile = $this->getValue($this->getItemName($token), Redis::SERIALIZER_PHP);
$profile = $this->getValue($this->getItemName($token), self::REDIS_SERIALIZER_PHP);

if (false !== $profile) {
$profile = $this->createProfileFromData($token, $profile);
Expand All @@ -162,7 +167,7 @@ public function write(Profile $profile)
'time' => $profile->getTime(),
);

if ($this->setValue($this->getItemName($profile->getToken()), $data, $this->lifetime, Redis::SERIALIZER_PHP)) {
if ($this->setValue($this->getItemName($profile->getToken()), $data, $this->lifetime, self::REDIS_SERIALIZER_PHP)) {
// Add to index
$indexName = $this->getIndexName();

Expand Down Expand Up @@ -203,7 +208,7 @@ protected function getRedis()
$redis = new Redis;
$redis->connect($host, $port);

$redis->setOption(Redis::OPT_PREFIX, self::TOKEN_PREFIX);
$redis->setOption(self::REDIS_OPT_PREFIX, self::TOKEN_PREFIX);

$this->redis = $redis;
}
Expand Down Expand Up @@ -243,7 +248,7 @@ private function createProfileFromData($token, $data, $parent = null)
continue;
}

if (!$childProfileData = $this->getValue($this->getItemName($token), Redis::SERIALIZER_PHP)) {
if (!$childProfileData = $this->getValue($this->getItemName($token), self::REDIS_SERIALIZER_PHP)) {
continue;
}

Expand Down Expand Up @@ -306,10 +311,10 @@ private function isItemNameValid($name)
*
* @return mixed
*/
private function getValue($key, $serializer = Redis::SERIALIZER_NONE)
private function getValue($key, $serializer = self::REDIS_SERIALIZER_NONE)
{
$redis = $this->getRedis();
$redis->setOption(Redis::OPT_SERIALIZER, $serializer);
$redis->setOption(self::REDIS_OPT_SERIALIZER, $serializer);

return $redis->get($key);
}
Expand All @@ -324,10 +329,10 @@ private function getValue($key, $serializer = Redis::SERIALIZER_NONE)
*
* @return Boolean
*/
private function setValue($key, $value, $expiration = 0, $serializer = Redis::SERIALIZER_NONE)
private function setValue($key, $value, $expiration = 0, $serializer = self::REDIS_SERIALIZER_NONE)
{
$redis = $this->getRedis();
$redis->setOption(Redis::OPT_SERIALIZER, $serializer);
$redis->setOption(self::REDIS_OPT_SERIALIZER, $serializer);

return $redis->setex($key, $expiration, $value);
}
Expand All @@ -344,7 +349,7 @@ private function setValue($key, $value, $expiration = 0, $serializer = Redis::SE
private function appendValue($key, $value, $expiration = 0)
{
$redis = $this->getRedis();
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
$redis->setOption(self::REDIS_OPT_SERIALIZER, self::REDIS_SERIALIZER_NONE);

if ($redis->exists($key)) {
$redis->append($key, $value);
Expand Down

0 comments on commit 00d43c6

Please sign in to comment.