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 sub _sock_result_bulk {
63 warn "# len: ",dump($len);
64 return undef if $len eq "nil\r\n";
66 read($sock, $v, $len) || die $!;
67 warn "# v: ",dump($v);
69 read($sock, $crlf, 2); # skip cr/lf
73 =head1 Connection Handling
84 close( $sock ) || warn $!;
89 $r->ping || die "no server?";
94 print $sock "PING\r\n";
96 die "ping failed, got ", dump($pong) unless $pong eq "+PONG\r\n";
99 =head1 Commands operating on string values
103 $r->set( foo => 'bar', $new );
108 my ( $self, $k, $v, $new ) = @_;
109 print $sock ( $new ? "SETNX" : "SET" ) . " $k " . length($v) . "\r\n$v\r\n";
111 confess dump($ok) unless $ok eq "+OK\r\n";
116 my $value = $r->get( 'foo' );
121 my ( $self, $k ) = @_;
122 print $sock "GET $k\r\n";
129 $r->incr('tripplets', 3);
136 my ( $self, $key, $value ) = @_;
137 if ( defined $value ) {
138 print $sock "INCRBY $key $value\r\n";
140 print $sock "INCR $key\r\n";
148 $r->decr('tripplets', 3);
153 my ( $self, $key, $value ) = @_;
154 if ( defined $value ) {
155 print $sock "DECRBY $key $value\r\n";
157 print $sock "DECR $key\r\n";
164 $r->exists( 'key' ) && print "got key!";
169 my ( $self, $key ) = @_;
170 print $sock "EXISTS $key\r\n";
176 $r->del( 'key' ) || warn "key doesn't exist";
181 my ( $self, $key ) = @_;
182 print $sock "DEL $key\r\n";
188 $r->type( 'key' ); # = string
193 my ( $self, $key ) = @_;
194 print $sock "TYPE $key\r\n";
198 =head1 Commands operating on the key space
202 my @keys = $r->keys( '*glob_pattern*' );
207 my ( $self, $glob ) = @_;
208 print $sock "KEYS $glob\r\n";
209 return split(/\s/, _sock_result_bulk());
214 my $key = $r->randomkey;
219 my ( $self, $glob ) = @_;
220 print $sock "RANDOMKEY\r\n";
226 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
230 Please report any bugs or feature requests to C<bug-redis at rt.cpan.org>, or through
231 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Redis>. I will be notified, and then you'll
232 automatically be notified of progress on your bug as I make changes.
239 You can find documentation for this module with the perldoc command.
244 You can also look for information at:
248 =item * RT: CPAN's request tracker
250 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Redis>
252 =item * AnnoCPAN: Annotated CPAN documentation
254 L<http://annocpan.org/dist/Redis>
258 L<http://cpanratings.perl.org/d/Redis>
262 L<http://search.cpan.org/dist/Redis>
267 =head1 ACKNOWLEDGEMENTS
270 =head1 COPYRIGHT & LICENSE
272 Copyright 2009 Dobrica Pavlinusic, all rights reserved.
274 This program is free software; you can redistribute it and/or modify it
275 under the same terms as Perl itself.