/[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 14 by dpavlin, Sat Mar 21 23:36:26 2009 UTC revision 20 by dpavlin, Sun Mar 22 09:51:34 2009 UTC
# Line 75  sub _sock_ok { Line 75  sub _sock_ok {
75          confess dump($ok) unless $ok eq "+OK\r\n";          confess dump($ok) unless $ok eq "+OK\r\n";
76  }  }
77    
78    sub _sock_send {
79            my $self = shift;
80            print $sock join(' ',@_) . "\r\n";
81            _sock_result();
82    }
83    
84    sub _sock_send_bulk {
85            my ( $self, $command, $key, $value ) = @_;
86            print $sock "$command $key " . length($value) . "\r\n$value\r\n";
87            _sock_ok();
88    }
89    
90    
91  =head1 Connection Handling  =head1 Connection Handling
92    
93  =head2 quit  =head2 quit
# Line 110  sub ping { Line 123  sub ping {
123  =cut  =cut
124    
125  sub set {  sub set {
126          my ( $self, $k, $v, $new ) = @_;          my ( $self, $key, $value, $new ) = @_;
127          print $sock ( $new ? "SETNX" : "SET" ) . " $k " . length($v) . "\r\n$v\r\n";          $self->_sock_send_bulk( "SET" . ( $new ? 'NX' : '' ), $key, $value );
         _sock_ok();  
128  }  }
129    
130  =head2 get  =head2 get
# Line 227  sub randomkey { Line 239  sub randomkey {
239    
240  =head2 rename  =head2 rename
241    
242    my $ok = $r->rename( 'old-key', 'new-key', $only_if_new );    my $ok = $r->rename( 'old-key', 'new-key', $new );
243    
244  =cut  =cut
245    
# Line 237  sub rename { Line 249  sub rename {
249          _sock_ok();          _sock_ok();
250  }  }
251    
252    =head2 dbsize
253    
254      my $nr_keys = $r->dbsize;
255    
256    =cut
257    
258    sub dbsize {
259            my ( $self ) = @_;
260            print $sock "DBSIZE\r\n";
261            _sock_result();
262    }
263    
264    =head1 Commands operating on lists
265    
266    =head2 rpush
267    
268      $r->rpush( $key, $value );
269    
270    =cut
271    
272    sub rpush {
273            my ( $self, $key, $value ) = @_;
274            $self->_sock_send_bulk('RPUSH', $key, $value);
275    }
276    
277    =head2 lpush
278    
279      $r->lpush( $key, $value );
280    
281    =cut
282    
283    sub lpush {
284            my ( $self, $key, $value ) = @_;
285            $self->_sock_send_bulk('LPUSH', $key, $value);
286    }
287    
288    =head2 llen
289    
290      $r->llen( $key );
291    
292    =cut
293    
294    sub llen {
295            my ( $self, $key ) = @_;
296            $self->_sock_send( 'llen', $key );
297    }
298    
299  =head1 AUTHOR  =head1 AUTHOR
300    
301  Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>

Legend:
Removed from v.14  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC 1.1.26