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(); |
|
warn "# $key = $count"; |
|
|
return $count; |
|
138 |
} |
} |
139 |
|
|
140 |
=head2 decr |
=head2 decr |
151 |
} else { |
} else { |
152 |
print $sock "DECR $key\r\n"; |
print $sock "DECR $key\r\n"; |
153 |
} |
} |
154 |
my $count = <$sock>; |
sock_result(); |
|
warn "# $key = $count"; |
|
|
return $count; |
|
155 |
} |
} |
156 |
|
|
157 |
=head2 exists |
=head2 exists |
163 |
sub exists { |
sub exists { |
164 |
my ( $self, $key ) = @_; |
my ( $self, $key ) = @_; |
165 |
print $sock "EXISTS $key\r\n"; |
print $sock "EXISTS $key\r\n"; |
166 |
my $found = <$sock>; |
sock_result(); |
167 |
$found =~ s{\r\n$}{}; |
} |
168 |
warn "# exists $key = $found"; |
|
169 |
return $found; |
=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 |