X-Git-Url: http://git.rot13.org/?p=perl-Redis.git;a=blobdiff_plain;f=t%2F01-Redis.t;h=ddb3da60c3fcf317a32a48905eac59cb29ca1170;hp=24806956941df18cd8139ccbbd459c6077531b30;hb=5a4f5b7df615181414bd90265d47d819794b123e;hpb=64af4a24c8afba6e53561caa02d0c0f840c14dda diff --git a/t/01-Redis.t b/t/01-Redis.t index 2480695..ddb3da6 100755 --- a/t/01-Redis.t +++ b/t/01-Redis.t @@ -3,7 +3,8 @@ use warnings; use strict; -use Test::More tests => 92; +use Test::More tests => 106; +use Data::Dump qw/dump/; use lib 'lib'; @@ -15,12 +16,12 @@ 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 ) }; -ok( $@, 'set foo => bar new again failed' ); +ok( ! $o->setnx( foo => 'bar' ), 'setnx foo => bar fails' ); cmp_ok( $o->get( 'foo' ), 'eq', 'bar', 'get foo = bar' ); @@ -31,7 +32,6 @@ cmp_ok( $o->get( 'foo' ), 'eq', 'baz', 'get foo = baz' ); ok( $o->set( 'test-undef' => 42 ), 'set test-undef' ); ok( $o->set( 'test-undef' => undef ), 'set undef' ); ok( ! defined $o->get( 'test-undef' ), 'get undef' ); -diag $o->exists( 'test-undef' ); ok( $o->exists( 'test-undef' ), 'exists undef' ); $o->del('non-existant'); @@ -45,16 +45,18 @@ 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 ) { - my $key = 'key-' . $_; +foreach my $id ( 0 .. $key_next ) { + my $key = 'key-' . $id; push @keys, $key; - ok( $o->set( $key => $_ ), "set $key" ); + ok( $o->set( $key => $id ), "set $key" ); ok( $o->exists( $key ), "exists $key" ); - cmp_ok( $o->get( $key ), 'eq', $_, "get $key" ); - cmp_ok( $o->incr( 'key-next' ), '==', $_ + 1, 'incr' ); - cmp_ok( $o->decr( 'key-left' ), '==', $key_next - $_ - 1, 'decr' ); + cmp_ok( $o->get( $key ), 'eq', $id, "get $key" ); + cmp_ok( $o->incr( 'key-next' ), '==', $id + 1, 'incr' ); + cmp_ok( $o->decr( 'key-left' ), '==', $key_next - $id - 1, 'decr' ); } cmp_ok( $o->get( 'key-next' ), '==', $key_next + 1, 'key-next' ); @@ -62,8 +64,8 @@ cmp_ok( $o->get( 'key-next' ), '==', $key_next + 1, 'key-next' ); ok( $o->set('test-incrby', 0), 'test-incrby' ); ok( $o->set('test-decrby', 0), 'test-decry' ); foreach ( 1 .. 3 ) { - cmp_ok( $o->incr('test-incrby', 3), '==', $_ * 3, 'incrby 3' ); - cmp_ok( $o->decr('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' ); + cmp_ok( $o->incrby('test-incrby', 3), '==', $_ * 3, 'incrby 3' ); + cmp_ok( $o->decrby('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' ); } ok( $o->del( $_ ), "del $_" ) foreach map { "key-$_" } ( 'next', 'left' ); @@ -75,7 +77,6 @@ cmp_ok( $o->keys('key-*'), '==', $key_next + 1, 'key-*' ); is_deeply( [ $o->keys('key-*') ], [ @keys ], 'keys' ); ok( my $key = $o->randomkey, 'randomkey' ); -diag "key: $key"; ok( $o->rename( 'test-incrby', 'test-renamed' ), 'rename' ); ok( $o->exists( 'test-renamed' ), 'exists test-renamed' ); @@ -84,7 +85,7 @@ eval { $o->rename( 'test-decrby', 'test-renamed', 1 ) }; ok( $@, 'rename to existing key' ); ok( my $nr_keys = $o->dbsize, 'dbsize' ); -diag "dbsize: $nr_keys"; + diag "Commands operating on lists"; @@ -137,7 +138,7 @@ cmp_ok( $o->scard( $set ), '==', 0, 'scard' ); $o->sadd( 'test-set1', $_ ) foreach ( 'foo', 'bar', 'baz' ); $o->sadd( 'test-set2', $_ ) foreach ( 'foo', 'baz', 'xxx' ); -my $inter = [ 'baz', 'foo' ]; +my $inter = [ 'foo', 'baz' ]; is_deeply( [ $o->sinter( 'test-set1', 'test-set2' ) ], $inter, 'siter' ); @@ -157,6 +158,32 @@ 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 "Persistence control commands"; + +ok( $o->save, 'save' ); +ok( $o->bgsave, 'bgsave' ); +ok( $o->lastsave, 'lastsave' ); +#ok( $o->shutdown, 'shutdown' ); +diag "shutdown not tested"; + +diag "Remote server control commands"; + +ok( my $info = $o->info, 'info' ); +diag dump( $info ); + diag "Connection handling"; ok( $o->quit, 'quit' );