@@ -28,6 +28,11 @@ class Resque
2828 */
2929 protected static $ redisDatabase = 0 ;
3030
31+ /**
32+ * @var string auth of Redis database
33+ */
34+ protected static $ auth ;
35+
3136 /**
3237 * Given a host/port combination separated by a colon, set it as
3338 * the redis server that Resque will talk to.
@@ -37,11 +42,13 @@ class Resque
3742 * and returns a Resque_Redis instance, or
3843 * a nested array of servers with host/port pairs.
3944 * @param int $database
45+ * @param string $auth
4046 */
41- public static function setBackend ($ server , $ database = 0 )
47+ public static function setBackend ($ server , $ database = 0 , $ auth = null )
4248 {
4349 self ::$ redisServer = $ server ;
4450 self ::$ redisDatabase = $ database ;
51+ self ::$ auth = $ auth ;
4552 self ::$ redis = null ;
4653 }
4754
@@ -62,6 +69,10 @@ public static function redis()
6269 self ::$ redis = new Resque_Redis (self ::$ redisServer , self ::$ redisDatabase );
6370 }
6471
72+ if (!empty (self ::$ auth )) {
73+ self ::$ redis ->auth (self ::$ auth );
74+ }
75+
6576 return self ::$ redis ;
6677 }
6778
@@ -141,9 +152,9 @@ public static function pop($queue)
141152 public static function dequeue ($ queue , $ items = Array ())
142153 {
143154 if (count ($ items ) > 0 ) {
144- return self ::removeItems ($ queue , $ items );
155+ return self ::removeItems ($ queue , $ items );
145156 } else {
146- return self ::removeList ($ queue );
157+ return self ::removeList ($ queue );
147158 }
148159 }
149160
@@ -213,10 +224,11 @@ public static function size($queue)
213224 * @param string $class The name of the class that contains the code to execute the job.
214225 * @param array $args Any optional arguments that should be passed when the job is executed.
215226 * @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
216228 *
217229 * @return string|boolean Job ID when the job was created, false if creation was cancelled due to beforeEnqueue
218230 */
219- public static function enqueue ($ queue , $ class , $ args = null , $ trackStatus = false )
231+ public static function enqueue ($ queue , $ class , $ args = null , $ trackStatus = false , $ prefix = "" )
220232 {
221233 $ id = Resque::generateJobId ();
222234 $ hookParams = array (
@@ -232,7 +244,7 @@ public static function enqueue($queue, $class, $args = null, $trackStatus = fals
232244 return false ;
233245 }
234246
235- Resque_Job::create ($ queue , $ class , $ args , $ trackStatus , $ id );
247+ Resque_Job::create ($ queue , $ class , $ args , $ trackStatus , $ id, $ prefix );
236248 Resque_Event::trigger ('afterEnqueue ' , $ hookParams );
237249
238250 return $ id ;
@@ -263,6 +275,20 @@ public static function queues()
263275 return $ queues ;
264276 }
265277
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+
266292 /**
267293 * Remove Items from the queue
268294 * Safely moving each item to a temporary queue before processing it
@@ -317,7 +343,7 @@ private static function removeItems($queue, $items = Array())
317343
318344 /**
319345 * 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}]
321347 * @private
322348 *
323349 * @params string $string redis result in json
@@ -330,24 +356,24 @@ private static function matchItem($string, $items)
330356 $ decoded = json_decode ($ string , true );
331357
332358 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+ }
344376 }
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- }
351377 }
352378 return false ;
353379 }
0 commit comments