6 use Test::More tests => 55;
14 ok( my $o = Redis->new(), 'new' );
16 ok( $o->ping, 'ping' );
18 ok( $o->set( foo => 'bar' ), 'set foo => bar' );
20 eval { $o->set( foo => 'bar', 1 ) };
21 ok( $@, 'set foo => bar new again failed' );
23 cmp_ok( $o->get( 'foo' ), 'eq', 'bar', 'get foo = bar' );
25 ok( $o->set( foo => 'baz' ), 'set foo => baz' );
27 cmp_ok( $o->get( 'foo' ), 'eq', 'baz', 'get foo = baz' );
29 $o->del('non-existant');
31 ok( ! $o->exists( 'non-existant' ), 'exists non-existant' );
32 ok( ! $o->get( 'non-existant' ), 'get non-existant' );
34 ok( $o->set('key-next' => 0), 'key-next = 0' );
38 ok( $o->set('key-left' => $key_next), 'key-left' );
42 foreach ( 0 .. $key_next ) {
43 my $key = 'key-' . $_;
45 ok( $o->set( $key => $_ ), "set $key" );
46 ok( $o->exists( $key ), "exists $key" );
47 cmp_ok( $o->get( $key ), 'eq', $_, "get $key" );
48 cmp_ok( $o->incr( 'key-next' ), '==', $_ + 1, 'incr' );
49 cmp_ok( $o->decr( 'key-left' ), '==', $key_next - $_ - 1, 'decr' );
52 cmp_ok( $o->get( 'key-next' ), '==', $key_next + 1, 'key-next' );
54 ok( $o->set('test-incrby', 0), 'test-incrby' );
55 ok( $o->set('test-decrby', 0), 'test-decry' );
57 cmp_ok( $o->incr('test-incrby', 3), '==', $_ * 3, 'incrby 3' );
58 cmp_ok( $o->decr('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' );
61 ok( $o->del( $_ ), "del $_" ) foreach map { "key-$_" } ( 'next', 'left' );
62 ok( ! $o->del('non-existing' ), 'del non-existing' );
64 cmp_ok( $o->type('foo'), 'eq', 'string', 'type' );
66 cmp_ok( $o->keys('key-*'), '==', $key_next + 1, 'key-*' );
67 is_deeply( [ $o->keys('key-*') ], [ @keys ], 'keys' );
69 ok( my $key = $o->randomkey, 'randomkey' );
72 ok( $o->rename( 'test-incrby', 'test-renamed' ), 'rename' );
73 ok( $o->exists( 'test-renamed' ), 'exists test-renamed' );
75 eval { $o->rename( 'test-decrby', 'test-renamed', 1 ) };
76 ok( $@, 'rename to existing key' );
78 ok( my $nr_keys = $o->dbsize, 'dbsize' );
79 diag "dbsize: $nr_keys";
81 diag "Commands operating on lists";
83 ok( $o->rpush( 'test-list' => 'foo' ), 'rpush' );
85 ok( $o->lpush( 'test-list' => 'foo' ), 'lpush' );
89 ok( $o->quit, 'quit' );