3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
use Test::More tests => 102; |
use Test::More tests => 106; |
7 |
|
use Data::Dump qw/dump/; |
8 |
|
|
9 |
use lib 'lib'; |
use lib 'lib'; |
10 |
|
|
16 |
|
|
17 |
ok( $o->ping, 'ping' ); |
ok( $o->ping, 'ping' ); |
18 |
|
|
19 |
|
|
20 |
diag "Commands operating on string values"; |
diag "Commands operating on string values"; |
21 |
|
|
22 |
ok( $o->set( foo => 'bar' ), 'set foo => bar' ); |
ok( $o->set( foo => 'bar' ), 'set foo => bar' ); |
23 |
|
|
24 |
eval { $o->set( foo => 'bar', 1 ) }; |
ok( ! $o->setnx( foo => 'bar' ), 'setnx foo => bar fails' ); |
|
ok( $@, 'set foo => bar new again failed' ); |
|
25 |
|
|
26 |
cmp_ok( $o->get( 'foo' ), 'eq', 'bar', 'get foo = bar' ); |
cmp_ok( $o->get( 'foo' ), 'eq', 'bar', 'get foo = bar' ); |
27 |
|
|
32 |
ok( $o->set( 'test-undef' => 42 ), 'set test-undef' ); |
ok( $o->set( 'test-undef' => 42 ), 'set test-undef' ); |
33 |
ok( $o->set( 'test-undef' => undef ), 'set undef' ); |
ok( $o->set( 'test-undef' => undef ), 'set undef' ); |
34 |
ok( ! defined $o->get( 'test-undef' ), 'get undef' ); |
ok( ! defined $o->get( 'test-undef' ), 'get undef' ); |
|
diag $o->exists( 'test-undef' ); |
|
35 |
ok( $o->exists( 'test-undef' ), 'exists undef' ); |
ok( $o->exists( 'test-undef' ), 'exists undef' ); |
36 |
|
|
37 |
$o->del('non-existant'); |
$o->del('non-existant'); |
64 |
ok( $o->set('test-incrby', 0), 'test-incrby' ); |
ok( $o->set('test-incrby', 0), 'test-incrby' ); |
65 |
ok( $o->set('test-decrby', 0), 'test-decry' ); |
ok( $o->set('test-decrby', 0), 'test-decry' ); |
66 |
foreach ( 1 .. 3 ) { |
foreach ( 1 .. 3 ) { |
67 |
cmp_ok( $o->incr('test-incrby', 3), '==', $_ * 3, 'incrby 3' ); |
cmp_ok( $o->incrby('test-incrby', 3), '==', $_ * 3, 'incrby 3' ); |
68 |
cmp_ok( $o->decr('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' ); |
cmp_ok( $o->decrby('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' ); |
69 |
} |
} |
70 |
|
|
71 |
ok( $o->del( $_ ), "del $_" ) foreach map { "key-$_" } ( 'next', 'left' ); |
ok( $o->del( $_ ), "del $_" ) foreach map { "key-$_" } ( 'next', 'left' ); |
77 |
is_deeply( [ $o->keys('key-*') ], [ @keys ], 'keys' ); |
is_deeply( [ $o->keys('key-*') ], [ @keys ], 'keys' ); |
78 |
|
|
79 |
ok( my $key = $o->randomkey, 'randomkey' ); |
ok( my $key = $o->randomkey, 'randomkey' ); |
|
diag "key: $key"; |
|
80 |
|
|
81 |
ok( $o->rename( 'test-incrby', 'test-renamed' ), 'rename' ); |
ok( $o->rename( 'test-incrby', 'test-renamed' ), 'rename' ); |
82 |
ok( $o->exists( 'test-renamed' ), 'exists test-renamed' ); |
ok( $o->exists( 'test-renamed' ), 'exists test-renamed' ); |
85 |
ok( $@, 'rename to existing key' ); |
ok( $@, 'rename to existing key' ); |
86 |
|
|
87 |
ok( my $nr_keys = $o->dbsize, 'dbsize' ); |
ok( my $nr_keys = $o->dbsize, 'dbsize' ); |
88 |
diag "dbsize: $nr_keys"; |
|
89 |
|
|
90 |
diag "Commands operating on lists"; |
diag "Commands operating on lists"; |
91 |
|
|
161 |
ok( $o->flushdb, 'flushdb' ); |
ok( $o->flushdb, 'flushdb' ); |
162 |
cmp_ok( $o->dbsize, '==', 0, 'empty' ); |
cmp_ok( $o->dbsize, '==', 0, 'empty' ); |
163 |
|
|
164 |
|
|
165 |
diag "Sorting"; |
diag "Sorting"; |
166 |
|
|
167 |
ok( $o->lpush( 'test-sort', $_ ), "put $_" ) foreach ( 1 .. 4 ); |
ok( $o->lpush( 'test-sort', $_ ), "put $_" ) foreach ( 1 .. 4 ); |
170 |
is_deeply( [ $o->sort( 'test-sort' ) ], [ 1,2,3,4 ], 'sort' ); |
is_deeply( [ $o->sort( 'test-sort' ) ], [ 1,2,3,4 ], 'sort' ); |
171 |
is_deeply( [ $o->sort( 'test-sort DESC' ) ], [ 4,3,2,1 ], 'sort DESC' ); |
is_deeply( [ $o->sort( 'test-sort DESC' ) ], [ 4,3,2,1 ], 'sort DESC' ); |
172 |
|
|
173 |
|
|
174 |
|
diag "Persistence control commands"; |
175 |
|
|
176 |
|
ok( $o->save, 'save' ); |
177 |
|
ok( $o->bgsave, 'bgsave' ); |
178 |
|
ok( $o->lastsave, 'lastsave' ); |
179 |
|
#ok( $o->shutdown, 'shutdown' ); |
180 |
|
diag "shutdown not tested"; |
181 |
|
|
182 |
|
diag "Remote server control commands"; |
183 |
|
|
184 |
|
ok( my $info = $o->info, 'info' ); |
185 |
|
diag dump( $info ); |
186 |
|
|
187 |
diag "Connection handling"; |
diag "Connection handling"; |
188 |
|
|
189 |
ok( $o->quit, 'quit' ); |
ok( $o->quit, 'quit' ); |