/[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 7 by dpavlin, Sat Mar 21 22:38:56 2009 UTC revision 13 by dpavlin, Sat Mar 21 23:26:46 2009 UTC
# Line 51  sub new { Line 51  sub new {
51          $self;          $self;
52  }  }
53    
54    sub _sock_result {
55            my $result = <$sock>;
56            warn "# result: ",dump( $result );
57            $result =~ s{\r\n$}{} || warn "can't find cr/lf";
58            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  =head1 Connection Handling  =head1 Connection Handling
74    
75  =head2 quit  =head2 quit
# Line 101  sub set { Line 120  sub set {
120  sub get {  sub get {
121          my ( $self, $k ) = @_;          my ( $self, $k ) = @_;
122          print $sock "GET $k\r\n";          print $sock "GET $k\r\n";
123          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;  
124  }  }
125    
126  =head2 incr  =head2 incr
# Line 119  sub get { Line 130  sub get {
130    
131  =cut  =cut
132    
133            
134    
135  sub incr {  sub incr {
136          my ( $self, $key, $value ) = @_;          my ( $self, $key, $value ) = @_;
137          if ( defined $value ) {          if ( defined $value ) {
# Line 126  sub incr { Line 139  sub incr {
139          } else {          } else {
140                  print $sock "INCR $key\r\n";                  print $sock "INCR $key\r\n";
141          }          }
142          my $count = <$sock>;          _sock_result();
143          warn "# $key = $count";  }
144          return $count;  
145    =head2 decr
146    
147      $r->decr('counter');
148      $r->decr('tripplets', 3);
149    
150    =cut
151    
152    sub decr {
153            my ( $self, $key, $value ) = @_;
154            if ( defined $value ) {
155                    print $sock "DECRBY $key $value\r\n";
156            } else {
157                    print $sock "DECR $key\r\n";
158            }
159            _sock_result();
160    }
161    
162    =head2 exists
163    
164      $r->exists( 'key' ) && print "got key!";
165    
166    =cut
167    
168    sub exists {
169            my ( $self, $key ) = @_;
170            print $sock "EXISTS $key\r\n";
171            _sock_result();
172    }
173    
174    =head2 del
175    
176      $r->del( 'key' ) || warn "key doesn't exist";
177    
178    =cut
179    
180    sub del {
181            my ( $self, $key ) = @_;
182            print $sock "DEL $key\r\n";
183            _sock_result();
184    }
185    
186    =head2 type
187    
188      $r->type( 'key' ); # = string
189    
190    =cut
191    
192    sub type {
193            my ( $self, $key ) = @_;
194            print $sock "TYPE $key\r\n";
195            _sock_result();
196    }
197    
198    =head1 Commands operating on the key space
199    
200    =head2 keys
201    
202      my @keys = $r->keys( '*glob_pattern*' );
203    
204    =cut
205    
206    sub keys {
207            my ( $self, $glob ) = @_;
208            print $sock "KEYS $glob\r\n";
209            return split(/\s/, _sock_result_bulk());
210    }
211    
212    =head2 randomkey
213    
214      my $key = $r->randomkey;
215    
216    =cut
217    
218    sub randomkey {
219            my ( $self, $glob ) = @_;
220            print $sock "RANDOMKEY\r\n";
221            _sock_result();
222  }  }
223    
224  =head1 AUTHOR  =head1 AUTHOR

Legend:
Removed from v.7  
changed lines
  Added in v.13

  ViewVC Help
Powered by ViewVC 1.1.26