Parent Directory | Revision Log
quit, ping
1 | package Redis; |
2 | |
3 | use warnings; |
4 | use strict; |
5 | |
6 | use IO::Socket::INET; |
7 | use Data::Dump qw/dump/; |
8 | |
9 | =head1 NAME |
10 | |
11 | Redis - The great new Redis! |
12 | |
13 | =cut |
14 | |
15 | our $VERSION = '0.01'; |
16 | |
17 | |
18 | =head1 SYNOPSIS |
19 | |
20 | Pure perl bindings for L<http://code.google.com/p/redis/> |
21 | |
22 | use Redis; |
23 | |
24 | my $r = Redis->new(); |
25 | |
26 | |
27 | |
28 | |
29 | =head1 FUNCTIONS |
30 | |
31 | =head2 new |
32 | |
33 | =cut |
34 | |
35 | our $sock; |
36 | my $server = '127.0.0.1:6379'; |
37 | |
38 | sub new { |
39 | my $class = shift; |
40 | my $self = {}; |
41 | bless($self, $class); |
42 | |
43 | warn "# opening socket to $server"; |
44 | |
45 | $sock ||= IO::Socket::INET->new( |
46 | PeerAddr => $server, |
47 | Proto => 'tcp', |
48 | ) || die $!; |
49 | |
50 | $self; |
51 | } |
52 | |
53 | =head1 Connection Handling |
54 | |
55 | =head2 quit |
56 | |
57 | $r->quit; |
58 | |
59 | =cut |
60 | |
61 | sub quit { |
62 | my $self = shift; |
63 | |
64 | close( $sock ) || warn $!; |
65 | } |
66 | |
67 | =head2 ping |
68 | |
69 | $r->ping || die "no server?"; |
70 | |
71 | =cut |
72 | |
73 | sub ping { |
74 | print $sock "PING\r\n"; |
75 | my $pong = <$sock>; |
76 | die "ping failed, got ", dump($pong) unless $pong eq "+PONG\r\n"; |
77 | } |
78 | |
79 | =head1 AUTHOR |
80 | |
81 | Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >> |
82 | |
83 | =head1 BUGS |
84 | |
85 | Please report any bugs or feature requests to C<bug-redis at rt.cpan.org>, or through |
86 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Redis>. I will be notified, and then you'll |
87 | automatically be notified of progress on your bug as I make changes. |
88 | |
89 | |
90 | |
91 | |
92 | =head1 SUPPORT |
93 | |
94 | You can find documentation for this module with the perldoc command. |
95 | |
96 | perldoc Redis |
97 | |
98 | |
99 | You can also look for information at: |
100 | |
101 | =over 4 |
102 | |
103 | =item * RT: CPAN's request tracker |
104 | |
105 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Redis> |
106 | |
107 | =item * AnnoCPAN: Annotated CPAN documentation |
108 | |
109 | L<http://annocpan.org/dist/Redis> |
110 | |
111 | =item * CPAN Ratings |
112 | |
113 | L<http://cpanratings.perl.org/d/Redis> |
114 | |
115 | =item * Search CPAN |
116 | |
117 | L<http://search.cpan.org/dist/Redis> |
118 | |
119 | =back |
120 | |
121 | |
122 | =head1 ACKNOWLEDGEMENTS |
123 | |
124 | |
125 | =head1 COPYRIGHT & LICENSE |
126 | |
127 | Copyright 2009 Dobrica Pavlinusic, all rights reserved. |
128 | |
129 | This program is free software; you can redistribute it and/or modify it |
130 | under the same terms as Perl itself. |
131 | |
132 | |
133 | =cut |
134 | |
135 | 1; # End of Redis |
ViewVC Help | |
Powered by ViewVC 1.1.26 |