Jan Henning Thorsen > Mojo-Redis > Mojo::Redis::Subscription

Download:
Mojo-Redis-0.9928.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Mojo::Redis::Subscription - Result of Mojo::Redis->subscribe()

SYNOPSIS ^

You can create a Mojo::Redis::Subscription object in two ways:

Either from Mojo::Redis:

  use Mojo::Redis;
  $r = Mojo::Redis->new;
  $s = $r->subscribe('foo'); # does also ->connect()
  print @{ $s->channels } # print "foo";

...or from Mojo::Redis::Subscription:

  use Mojo::Redis::Subscription;
  my $s = Mojo::Redis::Subscription->new;
  $s->channels(['foo']);
  $s->connect;

Either way you need to subscribe to an event:

  $s->on(message => sub {
      my($s, $message, $channel) = @_;
  });

  Mojo::IOLoop->start;

EVENTS ^

message

  $self->on(message => sub { my($self, $message, $channel) = @_; ... });

This event receive the messages sent over the channel.

data

  $self->on(data => sub { my($self, $data) = @_; ... });

This event receive all data sent over the channel. Example:

  0: ['subscribe', 'first_channel_name', 1];
  1: ['message', 'first_channel_name','yay!']

ATTRIBUTES ^

channels

Holds an array ref of channel names which this object subscribe to.

type

Describes the sort of subscription this object is using: subscribe or psubscribe.

METHODS ^

connect

Used to connect to the redis server and start subscribing to the "channels". This is called automatically from "subscribe" in Mojo::Redis.

disconnect

Will remove the connection to the redis server. This also happen when the object goes out of scope.

AUTHOR ^

Jan Henning Thorsen - jhthorsen@cpan.org

syntax highlighting: