/[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 11 by dpavlin, Sat Mar 21 23:09:48 2009 UTC revision 14 by dpavlin, Sat Mar 21 23:36:26 2009 UTC
# Line 58  sub _sock_result { Line 58  sub _sock_result {
58          return $result;          return $result;
59  }  }
60    
61    sub _sock_result_bulk {
62            my $len = <$sock>;
63            warn "# len: ",dump($len);
64            return undef if $len eq "nil\r\n";
65            my $v;
66            read($sock, $v, $len) || die $!;
67            warn "# v: ",dump($v);
68            my $crlf;
69            read($sock, $crlf, 2); # skip cr/lf
70            return $v;
71    }
72    
73    sub _sock_ok {
74            my $ok = <$sock>;
75            confess dump($ok) unless $ok eq "+OK\r\n";
76    }
77    
78  =head1 Connection Handling  =head1 Connection Handling
79    
80  =head2 quit  =head2 quit
# Line 95  sub ping { Line 112  sub ping {
112  sub set {  sub set {
113          my ( $self, $k, $v, $new ) = @_;          my ( $self, $k, $v, $new ) = @_;
114          print $sock ( $new ? "SETNX" : "SET" ) . " $k " . length($v) . "\r\n$v\r\n";          print $sock ( $new ? "SETNX" : "SET" ) . " $k " . length($v) . "\r\n$v\r\n";
115          my $ok = <$sock>;          _sock_ok();
         confess dump($ok) unless $ok eq "+OK\r\n";  
116  }  }
117    
118  =head2 get  =head2 get
# Line 108  sub set { Line 124  sub set {
124  sub get {  sub get {
125          my ( $self, $k ) = @_;          my ( $self, $k ) = @_;
126          print $sock "GET $k\r\n";          print $sock "GET $k\r\n";
127          my $len = <$sock>;          _sock_result_bulk();
 #       warn "# len: ",dump($len);  
         return undef if $len eq "nil\r\n";  
         my $v;  
         read($sock, $v, $len) || die $!;  
 #       warn "# v: ",dump($v);  
         my $crlf;  
         read($sock, $crlf, 2); # skip cr/lf  
         return $v;  
128  }  }
129    
130  =head2 incr  =head2 incr
# Line 187  sub del { Line 195  sub del {
195    
196  sub type {  sub type {
197          my ( $self, $key ) = @_;          my ( $self, $key ) = @_;
198          print $sock "type $key\r\n";          print $sock "TYPE $key\r\n";
199          _sock_result();          _sock_result();
200  }  }
201    
202    =head1 Commands operating on the key space
203    
204    =head2 keys
205    
206      my @keys = $r->keys( '*glob_pattern*' );
207    
208    =cut
209    
210    sub keys {
211            my ( $self, $glob ) = @_;
212            print $sock "KEYS $glob\r\n";
213            return split(/\s/, _sock_result_bulk());
214    }
215    
216    =head2 randomkey
217    
218      my $key = $r->randomkey;
219    
220    =cut
221    
222    sub randomkey {
223            my ( $self ) = @_;
224            print $sock "RANDOMKEY\r\n";
225            _sock_result();
226    }
227    
228    =head2 rename
229    
230      my $ok = $r->rename( 'old-key', 'new-key', $only_if_new );
231    
232    =cut
233    
234    sub rename {
235            my ( $self, $old, $new, $nx ) = @_;
236            print $sock "RENAME" . ( $nx ? 'NX' : '' ) . " $old $new\r\n";
237            _sock_ok();
238    }
239    
240  =head1 AUTHOR  =head1 AUTHOR
241    
242  Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>

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

  ViewVC Help
Powered by ViewVC 1.1.26