Created
November 3, 2009 20:27
-
-
Save miyagawa/225398 to your computer and use it in GitHub Desktop.
Resque client in Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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