feat: add a dummy set/get in the main route to try redis

This commit is contained in:
2025-12-18 07:28:24 +01:00
parent 6565be735d
commit acb1f63bae

View File

@@ -1,16 +1,45 @@
package Urupam::App; package Urupam::App;
use Mojo::Base 'Mojolicious'; use Mojo::Base 'Mojolicious';
use Moose; use Urupam::DB;
sub startup { sub startup {
my $self = shift; my $self = shift;
$self->helper(
db => sub {
my $c = shift;
$c->stash->{db} ||= Urupam::DB->new;
}
);
my $r = $self->routes; my $r = $self->routes;
$r->get('/')->to( $r->get('/')->to(
cb => sub { cb => sub {
my $c = shift; my $c = shift;
$c->render( text => 'Hello from urupam!' ); my $tx = $c->render_later->tx;
my $db = $c->db;
$db->set( 'test_key' => '123soleil' )->then(
sub {
$c->app->log->info('Value set: test_key => 123soleil');
return $db->get('test_key');
}
)->then(
sub {
my $value = shift;
$c->app->log->info("Value retrieved: $value");
$c->render( text => "ok\nRetrieved value: $value" );
undef $tx;
}
)->catch(
sub {
my $err = shift;
$c->app->log->error("DB error: $err");
$c->render( text => "ok\nError: $err", status => 500 );
undef $tx;
}
);
} }
); );
} }