From 3ee0c353e00f63be41f37a7839bf1a86027c0317 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 28 Jul 2015 12:36:11 +0200 Subject: [PATCH] Add basic helper to manipulate peers in redis --- vroom.pl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/vroom.pl b/vroom.pl index 86df6b3..d9b9acb 100755 --- a/vroom.pl +++ b/vroom.pl @@ -219,6 +219,38 @@ helper log_event => sub { return 1; }; +# Return peers from redis +helper get_peers => sub { + my $self = shift; + my $peers = {}; + foreach my $peer ($self->redis->hkeys('peers')){ + $peers->{$peer} = $self->get_peer($peer); + } + return $peers; +}; + +# Return a single peer +helper get_peer => sub { + my $self = shift; + my $peer = shift; + return Mojo::JSON::from_json($self->redis->hget('peers', $peer); +}; + +# Store peers in redis +helper add_peer => sub { + my $self = shift; + my $id = shift; + my $peer = shift; + return $self->redis->hset('peers', $id, Mojo::JSON::to_json($peer)); +}; + +# Remove a peer +helper del_peer => sub { + my $self = shift; + my $id = shift; + return $self->redis->hdel('peers', $id); +}; + # Return a list of event between 2 dates helper get_event_list => sub { my $self = shift; @@ -2352,6 +2384,9 @@ app->config( } ); +# Emptying peers in redis +app->redis->del('peers'); + app->log->info('Starting VROOM daemon'); # And start, lets VROOM !! app->start;