I am new for redis and currently I am using PHP resque for redis. How can I define a job in php resque?
Asked
Active
Viewed 535 times
0
-
Maybe this [http://stackoverflow.com/questions/11814445/what-is-the-proper-way-to-setup-and-use-php-resque](http://stackoverflow.com/questions/11814445/what-is-the-proper-way-to-setup-and-use-php-resque) would help ? – Wa0x6e Oct 30 '12 at 16:56
2 Answers
2
This has changed in the newest version of PHP-resque, released 13 October 2012. According to the changelog, "Wrap job arguments in an array to improve compatibility with ruby resque."
which means if you've upgraded to PHP-Resque 1.2 you will access jobs from $args[0].

greenmindpdx
- 21
- 1
0
Queueing Jobs
Jobs are queued as follows:
require_once 'lib/Resque.php';
// Required if redis is located elsewhere
Resque::setBackend('localhost:6379');
$args = array(
'name' => 'Chris'
);
Resque::enqueue('default', 'My_Job', $args); Defining Jobs
Each job should be in it's own class, and include a perform method.
class My_Job
{
public function perform()
{
// Work work work
echo $this->args['name'];
}
}
When the job is run, the class will be instantiated and any arguments will be set as an array on the instantiated object, and are accessible via $this->args.
Any exception thrown by a job will result in the job failing - be careful here and make sure you handle the exceptions that shouldn't result in a job failing.

Avinash Dubey
- 128
- 1
- 3
- 12
-
Avinash, I'm following the same steps on Windows7. Jobs are queued properly. I can see it from Redis console. But when I run the Resque command, Jobs are popped (count goes down in Redis Console) but job is empty. I checked this by putting fwrite in actual PHP-Resque library. Resque.php Class's pop method is fetching item ($item) but it is always empty. Any idea what can be wrong? Does this have something to do with Windows OS? Thanks. – Ashit Vora Jun 01 '13 at 07:00