7 use Data::Dump qw/dump/;
12 Redis - The great new Redis!
16 our $VERSION = '0.01';
21 Pure perl bindings for L<http://code.google.com/p/redis/>
37 my $server = '127.0.0.1:6379';
44 warn "# opening socket to $server";
46 $sock ||= IO::Socket::INET->new(
54 =head1 Connection Handling
65 close( $sock ) || warn $!;
70 $r->ping || die "no server?";
75 print $sock "PING\r\n";
77 die "ping failed, got ", dump($pong) unless $pong eq "+PONG\r\n";
80 =head1 Commands operating on string values
84 $r->set( foo => 'bar', $new );
89 my ( $self, $k, $v, $new ) = @_;
90 print $sock ( $new ? "SETNX" : "SET" ) . " $k " . length($v) . "\r\n$v\r\n";
92 confess dump($ok) unless $ok eq "+OK\r\n";
97 my $value = $r->get( 'foo' );
102 my ( $self, $k ) = @_;
103 print $sock "GET $k\r\n";
105 # warn "# len: ",dump($len);
106 return undef if $len eq "nil\r\n";
108 read($sock, $v, $len) || die $!;
109 # warn "# v: ",dump($v);
111 read($sock, $crlf, 2); # skip cr/lf
118 $r->incr('tripplets', 3);
123 my $result = <$sock>;
124 warn "# result: ",dump( $result );
125 $result =~ s{\r\n$}{} || warn "can't find cr/lf";
131 my ( $self, $key, $value ) = @_;
132 if ( defined $value ) {
133 print $sock "INCRBY $key $value\r\n";
135 print $sock "INCR $key\r\n";
143 $r->decr('tripplets', 3);
148 my ( $self, $key, $value ) = @_;
149 if ( defined $value ) {
150 print $sock "DECRBY $key $value\r\n";
152 print $sock "DECR $key\r\n";
159 $r->exists( 'key' ) && print "got key!";
164 my ( $self, $key ) = @_;
165 print $sock "EXISTS $key\r\n";
171 $r->del( 'key' ) || warn "key doesn't exist";
176 my ( $self, $key ) = @_;
177 print $sock "DEL $key\r\n";
183 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
187 Please report any bugs or feature requests to C<bug-redis at rt.cpan.org>, or through
188 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Redis>. I will be notified, and then you'll
189 automatically be notified of progress on your bug as I make changes.
196 You can find documentation for this module with the perldoc command.
201 You can also look for information at:
205 =item * RT: CPAN's request tracker
207 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Redis>
209 =item * AnnoCPAN: Annotated CPAN documentation
211 L<http://annocpan.org/dist/Redis>
215 L<http://cpanratings.perl.org/d/Redis>
219 L<http://search.cpan.org/dist/Redis>
224 =head1 ACKNOWLEDGEMENTS
227 =head1 COPYRIGHT & LICENSE
229 Copyright 2009 Dobrica Pavlinusic, all rights reserved.
231 This program is free software; you can redistribute it and/or modify it
232 under the same terms as Perl itself.