--- lib/Redis.pm 2009/03/21 23:36:26 14 +++ lib/Redis.pm 2009/03/22 09:51:34 20 @@ -75,6 +75,19 @@ confess dump($ok) unless $ok eq "+OK\r\n"; } +sub _sock_send { + my $self = shift; + print $sock join(' ',@_) . "\r\n"; + _sock_result(); +} + +sub _sock_send_bulk { + my ( $self, $command, $key, $value ) = @_; + print $sock "$command $key " . length($value) . "\r\n$value\r\n"; + _sock_ok(); +} + + =head1 Connection Handling =head2 quit @@ -110,9 +123,8 @@ =cut sub set { - my ( $self, $k, $v, $new ) = @_; - print $sock ( $new ? "SETNX" : "SET" ) . " $k " . length($v) . "\r\n$v\r\n"; - _sock_ok(); + my ( $self, $key, $value, $new ) = @_; + $self->_sock_send_bulk( "SET" . ( $new ? 'NX' : '' ), $key, $value ); } =head2 get @@ -227,7 +239,7 @@ =head2 rename - my $ok = $r->rename( 'old-key', 'new-key', $only_if_new ); + my $ok = $r->rename( 'old-key', 'new-key', $new ); =cut @@ -237,6 +249,53 @@ _sock_ok(); } +=head2 dbsize + + my $nr_keys = $r->dbsize; + +=cut + +sub dbsize { + my ( $self ) = @_; + print $sock "DBSIZE\r\n"; + _sock_result(); +} + +=head1 Commands operating on lists + +=head2 rpush + + $r->rpush( $key, $value ); + +=cut + +sub rpush { + my ( $self, $key, $value ) = @_; + $self->_sock_send_bulk('RPUSH', $key, $value); +} + +=head2 lpush + + $r->lpush( $key, $value ); + +=cut + +sub lpush { + my ( $self, $key, $value ) = @_; + $self->_sock_send_bulk('LPUSH', $key, $value); +} + +=head2 llen + + $r->llen( $key ); + +=cut + +sub llen { + my ( $self, $key ) = @_; + $self->_sock_send( 'llen', $key ); +} + =head1 AUTHOR Dobrica Pavlinusic, C<< >>