sort
[perl-Redis.git] / t / 01-Redis.t
index 77fd499..177cacf 100755 (executable)
@@ -3,7 +3,7 @@
 use warnings;
 use strict;
 
-use Test::More tests => 86;
+use Test::More tests => 102;
 
 use lib 'lib';
 
@@ -15,6 +15,8 @@ ok( my $o = Redis->new(), 'new' );
 
 ok( $o->ping, 'ping' );
 
+diag "Commands operating on string values";
+
 ok( $o->set( foo => 'bar' ), 'set foo => bar' );
 
 eval { $o->set( foo => 'bar', 1 ) };
@@ -43,6 +45,8 @@ my $key_next = 3;
 
 ok( $o->set('key-left' => $key_next), 'key-left' );
 
+is_deeply( [ $o->mget( 'foo', 'key-next', 'key-left' ) ], [ 'baz', 0, 3 ], 'mget' );
+
 my @keys;
 
 foreach ( 0 .. $key_next ) {
@@ -115,7 +119,8 @@ cmp_ok( $o->lpop( $list ), 'eq', 'r1', 'lpop' );
 
 ok( ! $o->rpop( $list ), 'rpop' );
 
-# Commands operating on sets
+
+diag "Commands operating on sets";
 
 my $set = 'test-set';
 $o->del($set);
@@ -142,4 +147,29 @@ ok( $o->sinterstore( 'test-set-inter', 'test-set1', 'test-set2' ), 'sinterstore'
 
 cmp_ok( $o->scard( 'test-set-inter' ), '==', $#$inter + 1, 'cardinality of intersection' );
 
+
+diag "Multiple databases handling commands";
+
+ok( $o->select( 1 ), 'select' );
+ok( $o->select( 0 ), 'select' );
+
+ok( $o->move( 'foo', 1 ), 'move' );
+ok( ! $o->exists( 'foo' ), 'gone' );
+
+ok( $o->select( 1 ), 'select' );
+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' );