sort
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 23 Mar 2009 11:30:40 +0000 (11:30 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 23 Mar 2009 11:30:40 +0000 (11:30 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/Redis@47 447b33ff-793d-4489-8442-9bea7d161be5

lib/Redis.pm
t/01-Redis.t

index 36416c4..4fc7eea 100644 (file)
@@ -536,6 +536,17 @@ sub flushall {
        $self->_sock_send_ok('flushall');
 }
 
+=head1 Sorting
+
+  $r->sort("key BY pattern LIMIT start end GET pattern ASC|DESC ALPHA');
+
+=cut
+
+sub sort {
+       my ( $self, $sort ) = @_;
+       $self->_sock_result_bulk_list( "SORT $sort" );
+}
+
 =head1 AUTHOR
 
 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
index 7c9ec64..177cacf 100755 (executable)
@@ -3,7 +3,7 @@
 use warnings;
 use strict;
 
-use Test::More tests => 95;
+use Test::More tests => 102;
 
 use lib 'lib';
 
@@ -162,6 +162,14 @@ ok( $o->exists( 'foo' ), 'exists' );
 ok( $o->flushdb, 'flushdb' );
 cmp_ok( $o->dbsize, '==', 0, 'empty' );
 
+diag "Sorting";
+
+ok( $o->lpush( 'test-sort', $_ ), "put $_" ) foreach ( 1 .. 4 );
+cmp_ok( $o->llen( 'test-sort' ), '==', 4, 'llen' );
+
+is_deeply( [ $o->sort( 'test-sort' )      ], [ 1,2,3,4 ], 'sort' );
+is_deeply( [ $o->sort( 'test-sort DESC' ) ], [ 4,3,2,1 ], 'sort DESC' );
+
 diag "Connection handling";
 
 ok( $o->quit, 'quit' );