@@ -28,6 +28,11 @@ class Resque
28
28
*/
29
29
protected static $ redisDatabase = 0 ;
30
30
31
+ /**
32
+ * @var string auth of Redis database
33
+ */
34
+ protected static $ auth ;
35
+
31
36
/**
32
37
* Given a host/port combination separated by a colon, set it as
33
38
* the redis server that Resque will talk to.
@@ -37,11 +42,13 @@ class Resque
37
42
* and returns a Resque_Redis instance, or
38
43
* a nested array of servers with host/port pairs.
39
44
* @param int $database
45
+ * @param string $auth
40
46
*/
41
- public static function setBackend ($ server , $ database = 0 )
47
+ public static function setBackend ($ server , $ database = 0 , $ auth = null )
42
48
{
43
49
self ::$ redisServer = $ server ;
44
50
self ::$ redisDatabase = $ database ;
51
+ self ::$ auth = $ auth ;
45
52
self ::$ redis = null ;
46
53
}
47
54
@@ -62,6 +69,10 @@ public static function redis()
62
69
self ::$ redis = new Resque_Redis (self ::$ redisServer , self ::$ redisDatabase );
63
70
}
64
71
72
+ if (!empty (self ::$ auth )) {
73
+ self ::$ redis ->auth (self ::$ auth );
74
+ }
75
+
65
76
return self ::$ redis ;
66
77
}
67
78
@@ -141,9 +152,9 @@ public static function pop($queue)
141
152
public static function dequeue ($ queue , $ items = Array ())
142
153
{
143
154
if (count ($ items ) > 0 ) {
144
- return self ::removeItems ($ queue , $ items );
155
+ return self ::removeItems ($ queue , $ items );
145
156
} else {
146
- return self ::removeList ($ queue );
157
+ return self ::removeList ($ queue );
147
158
}
148
159
}
149
160
@@ -213,10 +224,11 @@ public static function size($queue)
213
224
* @param string $class The name of the class that contains the code to execute the job.
214
225
* @param array $args Any optional arguments that should be passed when the job is executed.
215
226
* @param boolean $trackStatus Set to true to be able to monitor the status of a job.
227
+ * @param string $prefix The prefix needs to be set for the status key
216
228
*
217
229
* @return string|boolean Job ID when the job was created, false if creation was cancelled due to beforeEnqueue
218
230
*/
219
- public static function enqueue ($ queue , $ class , $ args = null , $ trackStatus = false )
231
+ public static function enqueue ($ queue , $ class , $ args = null , $ trackStatus = false , $ prefix = "" )
220
232
{
221
233
$ id = Resque::generateJobId ();
222
234
$ hookParams = array (
@@ -232,7 +244,7 @@ public static function enqueue($queue, $class, $args = null, $trackStatus = fals
232
244
return false ;
233
245
}
234
246
235
- Resque_Job::create ($ queue , $ class , $ args , $ trackStatus , $ id );
247
+ Resque_Job::create ($ queue , $ class , $ args , $ trackStatus , $ id, $ prefix );
236
248
Resque_Event::trigger ('afterEnqueue ' , $ hookParams );
237
249
238
250
return $ id ;
@@ -263,6 +275,20 @@ public static function queues()
263
275
return $ queues ;
264
276
}
265
277
278
+ /**
279
+ * Retrieve all the items of a queue with Redis
280
+ *
281
+ * @return array Array of items.
282
+ */
283
+ public static function items ($ queue , $ start = 0 , $ stop = -1 )
284
+ {
285
+ $ list = self ::redis ()->lrange ('queue: ' . $ queue , $ start , $ stop );
286
+ if (!is_array ($ list )) {
287
+ $ list = array ();
288
+ }
289
+ return $ list ;
290
+ }
291
+
266
292
/**
267
293
* Remove Items from the queue
268
294
* Safely moving each item to a temporary queue before processing it
@@ -317,7 +343,7 @@ private static function removeItems($queue, $items = Array())
317
343
318
344
/**
319
345
* matching item
320
- * item can be ['class'] or ['class' => 'id'] or ['class' => {: foo => 1, : bar => 2}]
346
+ * item can be ['class'] or ['class' => 'id'] or ['class' => {' foo' => 1, ' bar' => 2}]
321
347
* @private
322
348
*
323
349
* @params string $string redis result in json
@@ -330,24 +356,24 @@ private static function matchItem($string, $items)
330
356
$ decoded = json_decode ($ string , true );
331
357
332
358
foreach ($ items as $ key => $ val ) {
333
- # class name only ex: item[0] = ['class']
334
- if (is_numeric ($ key )) {
335
- if ($ decoded ['class ' ] == $ val ) {
336
- return true ;
337
- }
338
- # class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}]
339
- } elseif (is_array ($ val )) {
340
- $ decodedArgs = (array )$ decoded ['args ' ][0 ];
341
- if ($ decoded ['class ' ] == $ key &&
342
- count ($ decodedArgs ) > 0 && count (array_diff ($ decodedArgs , $ val )) == 0 ) {
343
- return true ;
359
+ # class name only ex: item[0] = ['class']
360
+ if (is_numeric ($ key )) {
361
+ if ($ decoded ['class ' ] == $ val ) {
362
+ return true ;
363
+ }
364
+ # class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}]
365
+ } elseif (is_array ($ val )) {
366
+ $ decodedArgs = (array )$ decoded ['args ' ][0 ];
367
+ if ($ decoded ['class ' ] == $ key &&
368
+ count ($ decodedArgs ) > 0 && count (array_diff ($ decodedArgs , $ val )) == 0 ) {
369
+ return true ;
370
+ }
371
+ # class name with ID, example: item[0] = ['class' => 'id']
372
+ } else {
373
+ if ($ decoded ['class ' ] == $ key && $ decoded ['id ' ] == $ val ) {
374
+ return true ;
375
+ }
344
376
}
345
- # class name with ID, example: item[0] = ['class' => 'id']
346
- } else {
347
- if ($ decoded ['class ' ] == $ key && $ decoded ['id ' ] == $ val ) {
348
- return true ;
349
- }
350
- }
351
377
}
352
378
return false ;
353
379
}
0 commit comments