/[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 23 by dpavlin, Sun Mar 22 13:09:15 2009 UTC revision 28 by dpavlin, Sun Mar 22 15:02:42 2009 UTC
# Line 63  sub _sock_read_bulk { Line 63  sub _sock_read_bulk {
63          warn "## bulk len: ",dump($len);          warn "## bulk len: ",dump($len);
64          return undef if $len eq "nil\r\n";          return undef if $len eq "nil\r\n";
65          my $v;          my $v;
66          read($sock, $v, $len) || die $!;          if ( $len > 0 ) {
67          warn "## bulk v: ",dump($v);                  read($sock, $v, $len) || die $!;
68                    warn "## bulk v: ",dump($v);
69            }
70          my $crlf;          my $crlf;
71          read($sock, $crlf, 2); # skip cr/lf          read($sock, $crlf, 2); # skip cr/lf
72          return $v;          return $v;
# Line 77  sub _sock_result_bulk { Line 79  sub _sock_result_bulk {
79          _sock_read_bulk();          _sock_read_bulk();
80  }  }
81    
82  sub _sock_ok {  sub __sock_ok {
83          my $ok = <$sock>;          my $ok = <$sock>;
84            return undef if $ok eq "nil\r\n";
85          confess dump($ok) unless $ok eq "+OK\r\n";          confess dump($ok) unless $ok eq "+OK\r\n";
86  }  }
87    
# Line 93  sub _sock_send_ok { Line 96  sub _sock_send_ok {
96          my $self = shift;          my $self = shift;
97          warn "## _sock_send_ok ",dump( @_ );          warn "## _sock_send_ok ",dump( @_ );
98          print $sock join(' ',@_) . "\r\n";          print $sock join(' ',@_) . "\r\n";
99          _sock_ok();          __sock_ok();
100    }
101    
102    sub __sock_send_bulk_raw {
103            my $self = shift;
104            warn "## _sock_send_bulk ",dump( @_ );
105            my $value = pop;
106            $value = '' unless defined $value; # FIXME errr? nil?
107            print $sock join(' ',@_) . ' ' . length($value) . "\r\n$value\r\n"
108  }  }
109    
110  sub _sock_send_bulk {  sub _sock_send_bulk {
111          my ( $self, $command, $key, $value ) = @_;          __sock_send_bulk_raw( @_ );
112          print $sock "$command $key " . length($value) . "\r\n$value\r\n";          __sock_ok();
         _sock_ok();  
113  }  }
114    
115    sub _sock_send_bulk_number {
116            __sock_send_bulk_raw( @_ );
117            my $v = _sock_result();
118            confess $v unless $v =~ m{^\-?\d+$};
119            return $v;
120    }
121    
122  =head1 Connection Handling  =head1 Connection Handling
123    
# Line 334  sub ltrim { Line 350  sub ltrim {
350    
351  sub lindex {  sub lindex {
352          my ( $self, $key, $index ) = @_;          my ( $self, $key, $index ) = @_;
353          $self->_sock_result_bulk( 'lindex', $key, $index );          $self->_sock_result_bulk( 'LINDEX', $key, $index );
354    }
355    
356    =head2 lset
357    
358      $r->lset( $key, $index, $value );
359    
360    =cut
361    
362    sub lset {
363            my ( $self, $key, $index, $value ) = @_;
364            $self->_sock_send_bulk( 'LSET', $key, $index, $value );
365  }  }
366    
367    =head2 lrem
368    
369      my $modified_count = $r->lrem( $key, $count, $value );
370    
371    =cut
372    
373    sub lrem {
374            my ( $self, $key, $count, $value ) = @_;
375            $self->_sock_send_bulk_number( 'LREM', $key, $count, $value );
376    }
377    
378    =head2 lpop
379    
380      my $value = $r->lpop( $key );
381    
382    =cut
383    
384    sub lpop {
385            my ( $self, $key ) = @_;
386            $self->_sock_result_bulk( 'lpop', $key );
387    }
388    
389    =head2 rpop
390    
391      my $value = $r->rpop( $key );
392    
393    =cut
394    
395    sub rpop {
396            my ( $self, $key ) = @_;
397            $self->_sock_result_bulk( 'rpop', $key );
398    }
399    
400  =head1 AUTHOR  =head1 AUTHOR
401    

Legend:
Removed from v.23  
changed lines
  Added in v.28

  ViewVC Help
Powered by ViewVC 1.1.26