From f5a339e21d14df3ad2b9377f92aa503e35ec7dcf Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 23 Mar 2009 11:30:40 +0000 Subject: [PATCH] sort git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/Redis@47 447b33ff-793d-4489-8442-9bea7d161be5 --- lib/Redis.pm | 11 +++++++++++ t/01-Redis.t | 10 +++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Redis.pm b/lib/Redis.pm index 36416c4..4fc7eea 100644 --- a/lib/Redis.pm +++ b/lib/Redis.pm @@ -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<< >> diff --git a/t/01-Redis.t b/t/01-Redis.t index 7c9ec64..177cacf 100755 --- a/t/01-Redis.t +++ b/t/01-Redis.t @@ -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' ); -- 2.20.1