8000 [HttpKernel] RedisProfilerStorage - Fix falling unit tests when Redis… · symfony/symfony@991474b · GitHub
[go: up one dir, main page]

Skip to content

Commit 991474b

Browse files
committed
[HttpKernel] RedisProfilerStorage - Fix falling unit tests when Redis extension is not available
1 parent dbd9568 commit 991474b

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/Symfony/Component/HttpKernel/Profiler/RedisProfilerStorage.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class RedisProfilerStorage implements ProfilerStorageInterface
2222
{
2323
const TOKEN_PREFIX = 'sf_profiler_';
2424

25+
const REDIS_OPT_SERIALIZER = 1;
26+
const REDIS_OPT_PREFIX = 2;
27+
const REDIS_SERIALIZER_NONE = 0;
28+
const REDIS_SERIALIZER_PHP = 1;
29+
2530
protected $dsn;
2631
protected $lifetime;
2732

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

54-
if (!$indexContent = $this->getValue($indexName, Redis::SERIALIZER_NONE)) {
59+
if (!$indexContent = $this->getValue($indexName, self::REDIS_SERIALIZER_NONE)) {
5560
return array();
5661
}
5762

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

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

108113
if (!$indexContent) {
109114
return false;
@@ -137,7 +142,7 @@ public function read($token)
137142
return false;
138143
}
139144

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

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

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

@@ -203,7 +208,7 @@ protected function getRedis()
203208
$redis = new Redis;
204209
$redis->connect($host, $port);
205210

206-
$redis->setOption(Redis::OPT_PREFIX, self::TOKEN_PREFIX);
211+
$redis->setOption(self::REDIS_OPT_PREFIX, self::TOKEN_PREFIX);
207212

208213
$this->redis = $redis;
209214
}
@@ -243,7 +248,7 @@ private function createProfileFromData($token, $data, $parent = null)
243248
continue;
244249
}
245250

246-
if (!$childProfileData = $this->getValue($this->getItemName($token), Redis::SERIALIZER_PHP)) {
251+
if (!$childProfileData = $this->getValue($this->getItemName($token), self::REDIS_SERIALIZER_PHP)) {
247252
continue;
248253
}
249254

@@ -306,10 +311,10 @@ private function isItemNameValid($name)
306311
*
307312
* @return mixed
308313
*/
309-
private function getValue($key, $serializer = Redis::SERIALIZER_NONE)
314+
private function getValue($key, $serializer = self::REDIS_SERIALIZER_NONE)
310315
{
311316
$redis = $this->getRedis();
312-
$redis->setOption(Redis::OPT_SERIALIZER, $serializer);
317+
$redis->setOption(self::REDIS_OPT_SERIALIZER, $serializer);
313318

314319
return $redis->get($key);
315320
}
@@ -324,10 +329,10 @@ private function getValue($key, $serializer = Redis::SERIALIZER_NONE)
324329
*
325330
* @return Boolean
326331
*/
327-
private function setValue($key, $value, $expiration = 0, $serializer = Redis::SERIALIZER_NONE)
332+
private function setValue($key, $value, $expiration = 0, $serializer = self::REDIS_SERIALIZER_NONE)
328333
{
329334
$redis = $this->getRedis();
330-
$redis->setOption(Redis::OPT_SERIALIZER, $serializer);
335+
$redis->setOption(self::REDIS_OPT_SERIALIZER, $serializer);
331336

332337
return $redis->setex($key, $expiration, $value);
333338
}
@@ -344,7 +349,7 @@ private function setValue($key, $value, $expiration = 0, $serializer = Redis::SE
344349
private function appendValue($key, $value, $expiration = 0)
345350
{
346351
$redis = $this->getRedis();
347-
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
352+
$redis->setOption(self::REDIS_OPT_SERIALIZER, self::REDIS_SERIALIZER_NONE);
348353

349354
if ($redis->exists($key)) {
350355
$redis->append($key, $value);

0 commit comments

Comments
 (0)
0