/[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 4 by dpavlin, Sat Mar 21 21:53:15 2009 UTC revision 8 by dpavlin, Sat Mar 21 22:48:46 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 111  sub get { Line 112  sub get {
112          return $v;          return $v;
113  }  }
114    
115    =head2 incr
116    
117      $r->incr('counter');
118      $r->incr('tripplets', 3);
119    
120    =cut
121    
122    sub incr {
123            my ( $self, $key, $value ) = @_;
124            if ( defined $value ) {
125                    print $sock "INCRBY $key $value\r\n";
126            } else {
127                    print $sock "INCR $key\r\n";
128            }
129            my $count = <$sock>;
130            warn "# $key = $count";
131            return $count;
132    }
133    
134    =head2 decr
135    
136      $r->decr('counter');
137      $r->decr('tripplets', 3);
138    
139    =cut
140    
141    sub decr {
142            my ( $self, $key, $value ) = @_;
143            if ( defined $value ) {
144                    print $sock "DECRBY $key $value\r\n";
145            } else {
146                    print $sock "DECR $key\r\n";
147            }
148            my $count = <$sock>;
149            warn "# $key = $count";
150            return $count;
151    }
152    
153  =head1 AUTHOR  =head1 AUTHOR
154    

Legend:
Removed from v.4  
changed lines
  Added in v.8

  ViewVC Help
Powered by ViewVC 1.1.26