119 |
|
|
120 |
=cut |
=cut |
121 |
|
|
122 |
|
sub sock_result { |
123 |
|
my $result = <$sock>; |
124 |
|
warn "# result: ",dump( $result ); |
125 |
|
$result =~ s{\r\n$}{} || warn "can't find cr/lf"; |
126 |
|
return $result; |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
sub incr { |
sub incr { |
131 |
my ( $self, $key, $value ) = @_; |
my ( $self, $key, $value ) = @_; |
132 |
if ( defined $value ) { |
if ( defined $value ) { |
134 |
} else { |
} else { |
135 |
print $sock "INCR $key\r\n"; |
print $sock "INCR $key\r\n"; |
136 |
} |
} |
137 |
my $count = <$sock>; |
sock_result(); |
138 |
warn "# $key = $count"; |
} |
139 |
return $count; |
|
140 |
|
=head2 decr |
141 |
|
|
142 |
|
$r->decr('counter'); |
143 |
|
$r->decr('tripplets', 3); |
144 |
|
|
145 |
|
=cut |
146 |
|
|
147 |
|
sub decr { |
148 |
|
my ( $self, $key, $value ) = @_; |
149 |
|
if ( defined $value ) { |
150 |
|
print $sock "DECRBY $key $value\r\n"; |
151 |
|
} else { |
152 |
|
print $sock "DECR $key\r\n"; |
153 |
|
} |
154 |
|
sock_result(); |
155 |
|
} |
156 |
|
|
157 |
|
=head2 exists |
158 |
|
|
159 |
|
$r->exists( 'key' ) && print "got key!"; |
160 |
|
|
161 |
|
=cut |
162 |
|
|
163 |
|
sub exists { |
164 |
|
my ( $self, $key ) = @_; |
165 |
|
print $sock "EXISTS $key\r\n"; |
166 |
|
sock_result(); |
167 |
|
} |
168 |
|
|
169 |
|
=head2 del |
170 |
|
|
171 |
|
$r->del( 'key' ) || warn "key doesn't exist"; |
172 |
|
|
173 |
|
=cut |
174 |
|
|
175 |
|
sub del { |
176 |
|
my ( $self, $key ) = @_; |
177 |
|
print $sock "DEL $key\r\n"; |
178 |
|
sock_result(); |
179 |
} |
} |
180 |
|
|
181 |
=head1 AUTHOR |
=head1 AUTHOR |