June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
50
Task/Simple-database/Perl-6/simple-database-2.pl6
Normal file
50
Task/Simple-database/Perl-6/simple-database-2.pl6
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env perl6
|
||||
use JSON::Fast ;
|
||||
multi MAIN('set', $topic, $message='', :$server='localhost', :$port='3333', :$json='') {
|
||||
my %msg = function => 'set' , topic=> $topic , message=> $message ;
|
||||
%msg{"message"} = from-json( $json ) if $json ;
|
||||
sendmsg( %msg , $server, $port) ;
|
||||
}
|
||||
multi MAIN('add', $topic, $json, :$server='localhost', :$port='3333' ) {
|
||||
my %msg = function => 'set' , topic=> $topic;
|
||||
%msg{"message"} = from-json( $json ) if $json ;
|
||||
sendmsg( %msg , $server, $port) ;
|
||||
}
|
||||
multi MAIN('get', $topic, :$server='localhost', :$port='3333') {
|
||||
my %msg = function => 'get' , topic=> $topic ;
|
||||
sendmsg( %msg , $server, $port) ;
|
||||
}
|
||||
multi MAIN('delete', $topic, :$server='localhost', :$port='3333') {
|
||||
my %msg = function => 'delete' , topic=> $topic ;
|
||||
sendmsg( %msg , $server, $port) ;
|
||||
}
|
||||
multi MAIN('dump', :$server='localhost', :$port='3333') {
|
||||
my %msg = function => 'dump' ;
|
||||
sendmsg( %msg , $server, $port) ;
|
||||
}
|
||||
multi MAIN('addindex', $key, :$server='localhost', :$port='3333') {
|
||||
my %msg = function => 'addindex', key => $key ;
|
||||
sendmsg( %msg , $server, $port) ;
|
||||
}
|
||||
multi MAIN('reportindex', $key, :$server='localhost', :$port='3333') {
|
||||
my %msg = function => 'reportindex', key => $key ;
|
||||
sendmsg( %msg , $server, $port) ;
|
||||
}
|
||||
multi MAIN('reportlastindex', $key, :$server='localhost', :$port='3333') {
|
||||
my %msg = function => 'reportlastindex', key => $key ;
|
||||
sendmsg( %msg , $server, $port) ;
|
||||
}
|
||||
multi MAIN('reportlast', :$server='localhost', :$port='3333') {
|
||||
my %msg = function => 'reportlast' ;
|
||||
sendmsg( %msg , $server, $port) ;
|
||||
}
|
||||
sub sendmsg( %msg , $server, $port){
|
||||
my $conn = await IO::Socket::Async.connect( $server , $port );
|
||||
$conn.print: to-json( %msg,:!pretty)~"\n";
|
||||
react {
|
||||
whenever $conn.Supply -> $data {
|
||||
print $data;
|
||||
$conn.close;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue