@@ -22,6 +22,11 @@ class RedisProfilerStorage implements ProfilerStorageInterface
22
22
{
23
23
const TOKEN_PREFIX = 'sf_profiler_ ' ;
24
24
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
+
25
30
protected $ dsn ;
26
31
protected $ lifetime ;
27
32
@@ -51,7 +56,7 @@ public function find($ip, $url, $limit, $method)
51
56
{
52
57
$ indexName = $ this ->getIndexName ();
53
58
54
- if (!$ indexContent = $ this ->getValue ($ indexName , Redis:: SERIALIZER_NONE )) {
59
+ if (!$ indexContent = $ this ->getValue ($ indexName , self :: REDIS_SERIALIZER_NONE )) {
55
60
return array ();
56
61
}
57
62
@@ -103,7 +108,7 @@ public function purge()
103
108
// delete only items from index
104
109
$ indexName = $ this ->getIndexName ();
105
110
106
- $ indexContent = $ this ->getValue ($ indexName , Redis:: SERIALIZER_NONE );
111
+ $ indexContent = $ this ->getValue ($ indexName , self :: REDIS_SERIALIZER_NONE );
107
112
108
113
if (!$ indexContent ) {
109
114
return false ;
@@ -137,7 +142,7 @@ public function read($token)
137
142
return false ;
138
143
}
139
144
140
- $ profile = $ this ->getValue ($ this ->getItemName ($ token ), Redis:: SERIALIZER_PHP );
145
+ $ profile = $ this ->getValue ($ this ->getItemName ($ token ), self :: REDIS_SERIALIZER_PHP );
141
146
142
147
if (false !== $ profile ) {
143
148
$ profile = $ this ->createProfileFromData ($ token , $ profile );
@@ -162,7 +167,7 @@ public function write(Profile $profile)
162
167
'time ' => $ profile ->getTime (),
163
168
);
164
169
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 )) {
166
171
// Add to index
167
172
$ indexName = $ this ->getIndexName ();
168
173
@@ -203,7 +208,7 @@ protected function getRedis()
203
208
$ redis = new Redis ;
204
209
$ redis ->connect ($ host , $ port );
205
210
206
- $ redis ->setOption (Redis:: OPT_PREFIX , self ::TOKEN_PREFIX );
211
+ $ redis ->setOption (self :: REDIS_OPT_PREFIX , self ::TOKEN_PREFIX );
207
212
208
213
$ this ->redis = $ redis ;
209
214
}
@@ -243,7 +248,7 @@ private function createProfileFromData($token, $data, $parent = null)
243
248
continue ;
244
249
}
245
250
246
- if (!$ childProfileData = $ this ->getValue ($ this ->getItemName ($ token ), Redis:: SERIALIZER_PHP )) {
251
+ if (!$ childProfileData = $ this ->getValue ($ this ->getItemName ($ token ), self :: REDIS_SERIALIZER_PHP )) {
247
252
continue ;
248
253
}
249
254
@@ -306,10 +311,10 @@ private function isItemNameValid($name)
306
311
*
307
312
* @return mixed
308
313
*/
309
- private function getValue ($ key , $ serializer = Redis:: SERIALIZER_NONE )
314
+ private function getValue ($ key , $ serializer = self :: REDIS_SERIALIZER_NONE )
310
315
{
311
316
$ redis = $ this ->getRedis ();
312
- $ redis ->setOption (Redis:: OPT_SERIALIZER , $ serializer );
317
+ $ redis ->setOption (self :: REDIS_OPT_SERIALIZER , $ serializer );
313
318
314
319
return $ redis ->get ($ key );
315
320
}
@@ -324,10 +329,10 @@ private function getValue($key, $serializer = Redis::SERIALIZER_NONE)
324
329
*
325
330
* @return Boolean
326
331
*/
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 )
328
333
{
329
334
$ redis = $ this ->getRedis ();
330
- $ redis ->setOption (Redis:: OPT_SERIALIZER , $ serializer );
335
+ $ redis ->setOption (self :: REDIS_OPT_SERIALIZER , $ serializer );
331
336
332
337
return $ redis ->setex ($ key , $ expiration , $ value );
333
338
}
@@ -344,7 +349,7 @@ private function setValue($key, $value, $expiration = 0, $serializer = Redis::SE
344
349
private function appendValue ($ key , $ value , $ expiration = 0 )
345
350
{
346
351
$ redis = $ this ->getRedis ();
347
- $ redis ->setOption (Redis:: OPT_SERIALIZER , Redis:: SERIALIZER_NONE );
352
+ $ redis ->setOption (self :: REDIS_OPT_SERIALIZER , self :: REDIS_SERIALIZER_NONE );
348
353
349
354
if ($ redis ->exists ($ key )) {
350
355
$ redis ->append ($ key , $ value );
0 commit comments