06895a77168cfd436f35d0215f082b3d7f3ee85b
[perl-Redis.git] / t / 01-Redis.t
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Test::More tests => 42;
7
8 use lib 'lib';
9
10 BEGIN {
11         use_ok( 'Redis' );
12 }
13
14 ok( my $o = Redis->new(), 'new' );
15
16 ok( $o->ping, 'ping' );
17
18 ok( $o->set( foo => 'bar' ), 'set foo => bar' );
19
20 eval { $o->set( foo => 'bar', 1 ) };
21 ok( $@, 'set foo => bar new again failed' );
22
23 cmp_ok( $o->get( 'foo' ), 'eq', 'bar', 'get foo = bar' );
24
25 ok( $o->set( foo => 'baz' ), 'set foo => baz' );
26
27 cmp_ok( $o->get( 'foo' ), 'eq', 'baz', 'get foo = baz' );
28
29 ok( ! $o->exists( 'non-existant' ), 'exists non-existant' );
30 ok( ! $o->get( 'non-existant' ), 'get non-existant' );
31
32 ok( $o->set('key-next' => 0), 'key-next = 0' );
33
34 my $key_next = 3;
35
36 ok( $o->set('key-left' => $key_next), 'key-left' );
37
38 foreach ( 0 .. $key_next ) {
39         ok(     $o->set( "key-$_" => $_ ),           "set key-$_" );
40         ok(  $o->exists( "key-$_"       ),           "exists key-$_" );
41         cmp_ok( $o->get( "key-$_"       ), 'eq', $_, "get key-$_" );
42         cmp_ok( $o->incr( 'key-next' ), '==', $_ + 1, 'incr' );
43         cmp_ok( $o->decr( 'key-left' ), '==', $key_next - $_ - 1, 'decr' );
44 }
45
46 cmp_ok( $o->get( 'key-next' ), '==', $key_next + 1, 'key-next' );
47
48 ok( $o->set('test-incrby', 0), 'test-incrby' );
49 ok( $o->set('test-decrby', 0), 'test-decry' );
50 foreach ( 1 .. 3 ) {
51         cmp_ok( $o->incr('test-incrby', 3), '==', $_ * 3, 'incrby 3' );
52         cmp_ok( $o->decr('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' );
53 }
54
55 ok( $o->quit, 'quit' );