Skip to content

Instantly share code, notes, and snippets.

@miyagawa
Created November 3, 2009 20:27
Show Gist options
  • Save miyagawa/225398 to your computer and use it in GitHub Desktop.
Save miyagawa/225398 to your computer and use it in GitHub Desktop.
Resque client in Perl
package Resque;
use Any::Moose;
use Redis;
use JSON;
has server => (is => 'rw', isa => 'Str', default => 'localhost:6379');
has redis => (is => 'rw', isa => 'Redis', lazy_build => 1);
sub _build_redis {
my $self = shift;
Redis->new(server => $self->server);
}
sub push {
my($self, $queue, $obj) = @_;
my $key = "resque:queue:$queue";
$self->redis->rpush($key, JSON::encode_json($obj));
}
sub pop {
my($self, $queue, $obj) = @_;
my $key = "resque:queue:$queue";
JSON::decode_json( $self->redis->lpop($key) );
}
my $r = Resque->new;
$r->push('default', { class => 'ShellJob', args => [ 'which', 'cat' ] });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment