X-Git-Url: http://git.rot13.org/?p=perl-Redis.git;a=blobdiff_plain;f=t%2F01-Redis.t;h=177cacf50cbb0edc4bf2cd942f4a45968428dbcc;hp=30d780dc78003a643da26c2ce5c3f4667ec42c70;hb=f5a339e21d14df3ad2b9377f92aa503e35ec7dcf;hpb=7b06790912537232a106266ab3777d548f86cfd3 diff --git a/t/01-Redis.t b/t/01-Redis.t index 30d780d..177cacf 100755 --- a/t/01-Redis.t +++ b/t/01-Redis.t @@ -3,7 +3,7 @@ use warnings; use strict; -use Test::More tests => 71; +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 ) }; @@ -26,6 +28,12 @@ ok( $o->set( foo => 'baz' ), 'set foo => baz' ); 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'); ok( ! $o->exists( 'non-existant' ), 'exists non-existant' ); @@ -37,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 ) { @@ -109,4 +119,57 @@ cmp_ok( $o->lpop( $list ), 'eq', 'r1', 'lpop' ); ok( ! $o->rpop( $list ), 'rpop' ); + +diag "Commands operating on sets"; + +my $set = 'test-set'; +$o->del($set); + +ok( $o->sadd( $set, 'foo' ), 'sadd' ); +ok( ! $o->sadd( $set, 'foo' ), 'sadd' ); +cmp_ok( $o->scard( $set ), '==', 1, 'scard' ); +ok( $o->sismember( $set, 'foo' ), 'sismember' ); + +cmp_ok( $o->type( $set ), 'eq', 'set', 'type is set' ); + +ok( $o->srem( $set, 'foo' ), 'srem' ); +ok( ! $o->srem( $set, 'foo' ), 'srem again' ); +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' ]; + +is_deeply( [ $o->sinter( 'test-set1', 'test-set2' ) ], $inter, 'siter' ); + +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' );