3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
use Test::More tests => 95; |
use Test::More tests => 108; |
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 |
|
ok( $o = Redis->new( server => 'localhost:6379' ), 'new with server' ); |
20 |
|
|
21 |
diag "Commands operating on string values"; |
diag "Commands operating on string values"; |
22 |
|
|
23 |
ok( $o->set( foo => 'bar' ), 'set foo => bar' ); |
ok( $o->set( foo => 'bar' ), 'set foo => bar' ); |
24 |
|
|
25 |
eval { $o->set( foo => 'bar', 1 ) }; |
ok( ! $o->setnx( foo => 'bar' ), 'setnx foo => bar fails' ); |
|
ok( $@, 'set foo => bar new again failed' ); |
|
26 |
|
|
27 |
cmp_ok( $o->get( 'foo' ), 'eq', 'bar', 'get foo = bar' ); |
cmp_ok( $o->get( 'foo' ), 'eq', 'bar', 'get foo = bar' ); |
28 |
|
|
33 |
ok( $o->set( 'test-undef' => 42 ), 'set test-undef' ); |
ok( $o->set( 'test-undef' => 42 ), 'set test-undef' ); |
34 |
ok( $o->set( 'test-undef' => undef ), 'set undef' ); |
ok( $o->set( 'test-undef' => undef ), 'set undef' ); |
35 |
ok( ! defined $o->get( 'test-undef' ), 'get undef' ); |
ok( ! defined $o->get( 'test-undef' ), 'get undef' ); |
|
diag $o->exists( 'test-undef' ); |
|
36 |
ok( $o->exists( 'test-undef' ), 'exists undef' ); |
ok( $o->exists( 'test-undef' ), 'exists undef' ); |
37 |
|
|
38 |
$o->del('non-existant'); |
$o->del('non-existant'); |
50 |
|
|
51 |
my @keys; |
my @keys; |
52 |
|
|
53 |
foreach ( 0 .. $key_next ) { |
foreach my $id ( 0 .. $key_next ) { |
54 |
my $key = 'key-' . $_; |
my $key = 'key-' . $id; |
55 |
push @keys, $key; |
push @keys, $key; |
56 |
ok( $o->set( $key => $_ ), "set $key" ); |
ok( $o->set( $key => $id ), "set $key" ); |
57 |
ok( $o->exists( $key ), "exists $key" ); |
ok( $o->exists( $key ), "exists $key" ); |
58 |
cmp_ok( $o->get( $key ), 'eq', $_, "get $key" ); |
cmp_ok( $o->get( $key ), 'eq', $id, "get $key" ); |
59 |
cmp_ok( $o->incr( 'key-next' ), '==', $_ + 1, 'incr' ); |
cmp_ok( $o->incr( 'key-next' ), '==', $id + 1, 'incr' ); |
60 |
cmp_ok( $o->decr( 'key-left' ), '==', $key_next - $_ - 1, 'decr' ); |
cmp_ok( $o->decr( 'key-left' ), '==', $key_next - $id - 1, 'decr' ); |
61 |
} |
} |
62 |
|
|
63 |
cmp_ok( $o->get( 'key-next' ), '==', $key_next + 1, 'key-next' ); |
cmp_ok( $o->get( 'key-next' ), '==', $key_next + 1, 'key-next' ); |
65 |
ok( $o->set('test-incrby', 0), 'test-incrby' ); |
ok( $o->set('test-incrby', 0), 'test-incrby' ); |
66 |
ok( $o->set('test-decrby', 0), 'test-decry' ); |
ok( $o->set('test-decrby', 0), 'test-decry' ); |
67 |
foreach ( 1 .. 3 ) { |
foreach ( 1 .. 3 ) { |
68 |
cmp_ok( $o->incr('test-incrby', 3), '==', $_ * 3, 'incrby 3' ); |
cmp_ok( $o->incrby('test-incrby', 3), '==', $_ * 3, 'incrby 3' ); |
69 |
cmp_ok( $o->decr('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' ); |
cmp_ok( $o->decrby('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' ); |
70 |
} |
} |
71 |
|
|
72 |
ok( $o->del( $_ ), "del $_" ) foreach map { "key-$_" } ( 'next', 'left' ); |
ok( $o->del( $_ ), "del $_" ) foreach map { "key-$_" } ( 'next', 'left' ); |
78 |
is_deeply( [ $o->keys('key-*') ], [ @keys ], 'keys' ); |
is_deeply( [ $o->keys('key-*') ], [ @keys ], 'keys' ); |
79 |
|
|
80 |
ok( my $key = $o->randomkey, 'randomkey' ); |
ok( my $key = $o->randomkey, 'randomkey' ); |
|
diag "key: $key"; |
|
81 |
|
|
82 |
ok( $o->rename( 'test-incrby', 'test-renamed' ), 'rename' ); |
ok( $o->rename( 'test-incrby', 'test-renamed' ), 'rename' ); |
83 |
ok( $o->exists( 'test-renamed' ), 'exists test-renamed' ); |
ok( $o->exists( 'test-renamed' ), 'exists test-renamed' ); |
86 |
ok( $@, 'rename to existing key' ); |
ok( $@, 'rename to existing key' ); |
87 |
|
|
88 |
ok( my $nr_keys = $o->dbsize, 'dbsize' ); |
ok( my $nr_keys = $o->dbsize, 'dbsize' ); |
89 |
diag "dbsize: $nr_keys"; |
|
90 |
|
|
91 |
diag "Commands operating on lists"; |
diag "Commands operating on lists"; |
92 |
|
|
139 |
$o->sadd( 'test-set1', $_ ) foreach ( 'foo', 'bar', 'baz' ); |
$o->sadd( 'test-set1', $_ ) foreach ( 'foo', 'bar', 'baz' ); |
140 |
$o->sadd( 'test-set2', $_ ) foreach ( 'foo', 'baz', 'xxx' ); |
$o->sadd( 'test-set2', $_ ) foreach ( 'foo', 'baz', 'xxx' ); |
141 |
|
|
142 |
my $inter = [ 'baz', 'foo' ]; |
my $inter = [ 'foo', 'baz' ]; |
143 |
|
|
144 |
is_deeply( [ $o->sinter( 'test-set1', 'test-set2' ) ], $inter, 'siter' ); |
is_deeply( [ $o->sinter( 'test-set1', 'test-set2' ) ], $inter, 'siter' ); |
145 |
|
|
162 |
ok( $o->flushdb, 'flushdb' ); |
ok( $o->flushdb, 'flushdb' ); |
163 |
cmp_ok( $o->dbsize, '==', 0, 'empty' ); |
cmp_ok( $o->dbsize, '==', 0, 'empty' ); |
164 |
|
|
165 |
|
|
166 |
|
diag "Sorting"; |
167 |
|
|
168 |
|
ok( $o->lpush( 'test-sort', $_ ), "put $_" ) foreach ( 1 .. 4 ); |
169 |
|
cmp_ok( $o->llen( 'test-sort' ), '==', 4, 'llen' ); |
170 |
|
|
171 |
|
is_deeply( [ $o->sort( 'test-sort' ) ], [ 1,2,3,4 ], 'sort' ); |
172 |
|
is_deeply( [ $o->sort( 'test-sort DESC' ) ], [ 4,3,2,1 ], 'sort DESC' ); |
173 |
|
|
174 |
|
|
175 |
|
diag "Persistence control commands"; |
176 |
|
|
177 |
|
ok( $o->save, 'save' ); |
178 |
|
ok( $o->bgsave, 'bgsave' ); |
179 |
|
ok( $o->lastsave, 'lastsave' ); |
180 |
|
#ok( $o->shutdown, 'shutdown' ); |
181 |
|
diag "shutdown not tested"; |
182 |
|
|
183 |
|
diag "Remote server control commands"; |
184 |
|
|
185 |
|
ok( my $info = $o->info, 'info' ); |
186 |
|
isa_ok( $info, 'HASH' ); |
187 |
|
diag dump( $info ); |
188 |
|
|
189 |
diag "Connection handling"; |
diag "Connection handling"; |
190 |
|
|
191 |
ok( $o->quit, 'quit' ); |
ok( $o->quit, 'quit' ); |