Skip to content

Instantly share code, notes, and snippets.

@und3f
Forked from Meettya/Author.pm
Created February 25, 2011 21:13
Show Gist options
  • Save und3f/844507 to your computer and use it in GitHub Desktop.
Save und3f/844507 to your computer and use it in GitHub Desktop.
package NoticeBackend::Author;
use Mojo::Base 'Mojolicious::Controller';
use 5.12.0;
use warnings;
use utf8;
use MojoX::Redis;
use Mojo::IOLoop;
my $redis = MojoX::Redis->new(server => '192.168.1.20:6379');
my ($redis_out);
sub get{
my $self = shift;
my $user_query = $self->req->is_xhr ?
$self->req->json->{'name'} : $self->param('name');
my $callback_name = $self->req->is_xhr ?
$self->req->json->{'callback'} : $self->param('callback');
my $data_out;
my $redis->ioloop(Mojo::IOLoop->new);
$redis->get( $user_query => sub {
my ($redis, $res) = @_;
$data_out = $res->[0];
$redis->stop;
});
$redis->start;
$self->render( text => "|$data_out|" );
};
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment