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(
56 warn "# result: ",dump( $result );
57 $result =~ s{\r\n$}{} || warn "can't find cr/lf";
61 =head1 Connection Handling
72 close( $sock ) || warn $!;
77 $r->ping || die "no server?";
82 print $sock "PING\r\n";
84 die "ping failed, got ", dump($pong) unless $pong eq "+PONG\r\n";
87 =head1 Commands operating on string values
91 $r->set( foo => 'bar', $new );
96 my ( $self, $k, $v, $new ) = @_;
97 print $sock ( $new ? "SETNX" : "SET" ) . " $k " . length($v) . "\r\n$v\r\n";
99 confess dump($ok) unless $ok eq "+OK\r\n";
104 my $value = $r->get( 'foo' );
109 my ( $self, $k ) = @_;
110 print $sock "GET $k\r\n";
112 # warn "# len: ",dump($len);
113 return undef if $len eq "nil\r\n";
115 read($sock, $v, $len) || die $!;
116 # warn "# v: ",dump($v);
118 read($sock, $crlf, 2); # skip cr/lf
125 $r->incr('tripplets', 3);
132 my ( $self, $key, $value ) = @_;
133 if ( defined $value ) {
134 print $sock "INCRBY $key $value\r\n";
136 print $sock "INCR $key\r\n";
144 $r->decr('tripplets', 3);
149 my ( $self, $key, $value ) = @_;
150 if ( defined $value ) {
151 print $sock "DECRBY $key $value\r\n";
153 print $sock "DECR $key\r\n";
160 $r->exists( 'key' ) && print "got key!";
165 my ( $self, $key ) = @_;
166 print $sock "EXISTS $key\r\n";
172 $r->del( 'key' ) || warn "key doesn't exist";
177 my ( $self, $key ) = @_;
178 print $sock "DEL $key\r\n";
184 $r->type( 'key' ); # = string
189 my ( $self, $key ) = @_;
190 print $sock "type $key\r\n";
196 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
200 Please report any bugs or feature requests to C<bug-redis at rt.cpan.org>, or through
201 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Redis>. I will be notified, and then you'll
202 automatically be notified of progress on your bug as I make changes.
209 You can find documentation for this module with the perldoc command.
214 You can also look for information at:
218 =item * RT: CPAN's request tracker
220 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Redis>
222 =item * AnnoCPAN: Annotated CPAN documentation
224 L<http://annocpan.org/dist/Redis>
228 L<http://cpanratings.perl.org/d/Redis>
232 L<http://search.cpan.org/dist/Redis>
237 =head1 ACKNOWLEDGEMENTS
240 =head1 COPYRIGHT & LICENSE
242 Copyright 2009 Dobrica Pavlinusic, all rights reserved.
244 This program is free software; you can redistribute it and/or modify it
245 under the same terms as Perl itself.