/[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 3 by dpavlin, Sat Mar 21 21:40:53 2009 UTC revision 5 by dpavlin, Sat Mar 21 22:20:51 2009 UTC
# Line 5  use strict; Line 5  use strict;
5    
6  use IO::Socket::INET;  use IO::Socket::INET;
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
8    use Carp qw/confess/;
9    
10  =head1 NAME  =head1 NAME
11    
# Line 80  sub ping { Line 81  sub ping {
81    
82  =head2 set  =head2 set
83    
84    $r->set( foo => 'bar' );    $r->set( foo => 'bar', $new );
85    
86  =cut  =cut
87    
88  sub set {  sub set {
89          my ( $self, $k, $v ) = @_;          my ( $self, $k, $v, $new ) = @_;
90          print $sock "SET $k " . length($v) . "\r\n$v\r\n";          print $sock ( $new ? "SETNX" : "SET" ) . " $k " . length($v) . "\r\n$v\r\n";
91          my $ok = <$sock>;          my $ok = <$sock>;
92          die dump($ok) unless $ok eq "+OK\r\n";          confess dump($ok) unless $ok eq "+OK\r\n";
93  }  }
94    
95  =head2 get  =head2 get
# Line 101  sub get { Line 102  sub get {
102          my ( $self, $k ) = @_;          my ( $self, $k ) = @_;
103          print $sock "GET $k\r\n";          print $sock "GET $k\r\n";
104          my $len = <$sock>;          my $len = <$sock>;
105    #       warn "# len: ",dump($len);
106            return undef if $len eq "nil\r\n";
107          my $v;          my $v;
108          read($sock, $v, $len) || die $!;          read($sock, $v, $len) || die $!;
109    #       warn "# v: ",dump($v);
110            my $crlf;
111            read($sock, $crlf, 2); # skip cr/lf
112          return $v;          return $v;
113  }  }
114    
115    
116    
117  =head1 AUTHOR  =head1 AUTHOR
118    
119  Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>

Legend:
Removed from v.3  
changed lines
  Added in v.5

  ViewVC Help
Powered by ViewVC 1.1.26