LasTres/lib/LasTres/Redis.pm

52 lines
935 B
Perl

package LasTres::Redis;
use v5.36.0;
use strict;
use warnings;
use feature 'signatures';
use parent 'Mojo::Redis';
use LasTres::Schema;
our $VERSION = $LasTres::Schema::VERSION;
{
my $self;
sub new {
my $class = shift;
if (!defined $self) {
$self = $class->SUPER::new(@_);
}
return $self;
}
}
sub prefix {
return "LasTres::Redis::$VERSION";
}
sub subscribe($self, $topic, $callback) {
$self->pubsub->listen($topic, sub($self, $message, $topic) {
$callback->($message, $topic, [$topic]);
});
}
sub publish($self, $topic, $message) {
$self->pubsub->notify($topic, $message);
}
sub pj_subscription($class, $pj) {
return prefix() . '::Subscriptions::PJ::' . $pj->uuid;
}
sub battle_key($class, $battle_uuid) {
return prefix() . '::Key::Battle' . $battle_uuid;
}
sub executing_frame_key($class) {
return prefix() . '::Key::Frame';
}
1;