/[Redis.pre-github]/lib/Redis.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/Redis.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 30 by dpavlin, Sun Mar 22 17:02:46 2009 UTC revision 36 by dpavlin, Sun Mar 22 18:05:12 2009 UTC
# Line 9  use Carp qw/confess/; Line 9  use Carp qw/confess/;
9    
10  =head1 NAME  =head1 NAME
11    
12  Redis - The great new Redis!  Redis - perl binding for Redis database
13    
14  =cut  =cut
15    
# Line 20  our $VERSION = '0.01'; Line 20  our $VERSION = '0.01';
20    
21  Pure perl bindings for L<http://code.google.com/p/redis/>  Pure perl bindings for L<http://code.google.com/p/redis/>
22    
23    This version support git version of Redis available at
24    L<git://github.com/antirez/redis>
25    
26      use Redis;      use Redis;
27    
28      my $r = Redis->new();      my $r = Redis->new();
29    
   
   
   
30  =head1 FUNCTIONS  =head1 FUNCTIONS
31    
32  =head2 new  =head2 new
# Line 79  sub _sock_result_bulk { Line 79  sub _sock_result_bulk {
79          _sock_read_bulk();          _sock_read_bulk();
80  }  }
81    
82    sub _sock_result_bulk_list {
83            my $self = shift;
84            warn "## _sock_result_bulk_list ",dump( @_ );
85    
86            my $size = $self->_sock_send( @_ );
87            confess $size unless $size > 0;
88            $size--;
89    
90            my @list = ( 0 .. $size );
91            foreach ( 0 .. $size ) {
92                    $list[ $_ ] = _sock_read_bulk();
93            }
94    
95            warn "## list = ", dump( @list );
96            return @list;
97    }
98    
99  sub __sock_ok {  sub __sock_ok {
100          my $ok = <$sock>;          my $ok = <$sock>;
101          return undef if $ok eq "nil\r\n";          return undef if $ok eq "nil\r\n";
# Line 276  sub dbsize { Line 293  sub dbsize {
293    
294  =head1 Commands operating on lists  =head1 Commands operating on lists
295    
296    See also L<Redis::List> for tie interface.
297    
298  =head2 rpush  =head2 rpush
299    
300    $r->rpush( $key, $value );    $r->rpush( $key, $value );
# Line 317  sub llen { Line 336  sub llen {
336    
337  sub lrange {  sub lrange {
338          my ( $self, $key, $start, $end ) = @_;          my ( $self, $key, $start, $end ) = @_;
339          my $size = $self->_sock_send('LRANGE', $key, $start, $end);          $self->_sock_result_bulk_list('LRANGE', $key, $start, $end);
   
         confess $size unless $size > 0;  
         $size--;  
   
         my @list = ( 0 .. $size );  
         foreach ( 0 .. $size ) {  
                 $list[ $_ ] = _sock_read_bulk();  
         }  
   
         warn "## lrange $key $start $end = [$size] ", dump( @list );  
         return @list;  
340  }  }
341    
342  =head2 ltrim  =head2 ltrim
# Line 421  sub srem { Line 429  sub srem {
429          $self->_sock_send_bulk_number( 'SREM', $key, $member );          $self->_sock_send_bulk_number( 'SREM', $key, $member );
430  }  }
431    
432    =head2 scard
433    
434      my $elements = $r->scard( $key );
435    
436    =cut
437    
438    sub scard {
439            my ( $self, $key ) = @_;
440            $self->_sock_send( 'SCARD', $key );
441    }
442    
443    =head2 sismember
444    
445      $r->sismember( $key, $member );
446    
447    =cut
448    
449    sub sismember {
450            my ( $self, $key, $member ) = @_;
451            $self->_sock_send_bulk_number( 'SISMEMBER', $key, $member );
452    }
453    
454    =head2 sinter
455    
456      $r->sinter( $key1, $key2, ... );
457    
458    =cut
459    
460    sub sinter {
461            my $self = shift;
462            $self->_sock_result_bulk_list( 'SINTER', @_ );
463    }
464    
465    =head2 sinterstore
466    
467      my $ok = $r->sinterstore( $dstkey, $key1, $key2, ... );
468    
469    =cut
470    
471    sub sinterstore {
472            my $self = shift;
473            $self->_sock_send_ok( 'SINTERSTORE', @_ );
474    }
475    
476  =head1 AUTHOR  =head1 AUTHOR
477    
478  Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>

Legend:
Removed from v.30  
changed lines
  Added in v.36

  ViewVC Help
Powered by ViewVC 1.1.26