Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
Commands | |||
======== | |||
* quit | |||
* ping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,9 +1,52 @@ | |||
use v6; | |||
|
|||
# =begin Pod | # =begin Pod | ||
# =head1 Redis | # =head1 Redis | ||
# Perl6 binding for Redis. | # Perl6 binding for Redis. | ||
# | # | ||
# =end Pod | # =end Pod | ||
|
|
||
module Redis; | class Redis; | ||
|
|||
has Str $.host = '127.0.0.1'; | |||
has Int $.port = 6379; | |||
has Str $.sock; # if sock is defined, use sock | |||
has Bool $.debug = False; | |||
has Real $.timeout = 0.0; # 0 means unlimited | |||
has IO::Socket $.conn; | |||
|
|||
method new(Str $server?, Bool :$debug?, Real :$timeout?) { | |||
my %config = {} | |||
if $server.defined { | |||
if $server ~~ m/^([\d+]+ %\.) ':' (\d+)$/ { | |||
%config<host> = $0.Str; | |||
%config<port> = $1.Int; | |||
} else { | |||
%config<sock> = $server; | |||
} | |||
} | |||
if $debug.defined { | |||
%config<debug> = $debug; | |||
} | |||
if $timeout.defined { | |||
%config<timeout> = $timeout; | |||
} | |||
return self.bless(*, |%config); | |||
} | |||
|
|||
method connect { | |||
my $conn; | |||
if $.sock.defined { | |||
say "unsupported"; | |||
} else { | |||
$conn = IO::Socket::INET.new(host => $.host, port => $.port); | |||
} | |||
$.conn = $conn; | |||
} | |||
|
|||
#method ping { | |||
#$.conn.send("PING\r\n"); | |||
#print($.conn.get); | |||
#} | |||
|
|
||
# vim: ft=perl6 | # vim: ft=perl6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,33 @@ | |||
use v6; | use v6; | ||
|
|
||
use Redis; | |||
use Test; | use Test; | ||
|
|||
my @new_tasks = \() => { | |||
'host' => '127.0.0.1', | |||
'port' => 6379, | |||
'debug' => False, | |||
'timeout' => 0.0, | |||
}, | |||
\('192.168.0.1:6379', debug => True, timeout => 3) => { | |||
'host' => '192.168.0.1', | |||
'port' => 6379, | |||
'debug' => True, | |||
'timeout' => 3, | |||
}, | |||
\('/path/to/redis.sock', debug => True, timeout => 3) => { | |||
'sock' => '/path/to/redis.sock', | |||
'debug' => True, | |||
'timeout' => 3, | |||
}; | |||
|
|||
plan [+] @new_tasks.map({ $_.value.elems }); | |||
|
|||
for @new_tasks -> $p { | |||
my $r = Redis.new(|$p.key); | |||
$p.value.map({ | |||
is_deeply $r."{.key}"(), .value; | |||
}); | |||
} | |||
|
|||
# vim: ft=perl6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
use v6; | |||
|
|||
use Redis; | |||
use Test; | |||
|
|||
plan 1; | |||
|
|||
{ | |||
my $r = Redis.new; | |||
my $failed = 0; | |||
try { | |||
$r.connect; | |||
CATCH { | |||
default { $failed = 1 } | |||
} | |||
} | |||
ok $failed, 'trying to connect wrong server throws exception'; | |||
} | |||
|
|||
# vim: ft=perl6 |