3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
use Test::More tests => 82; |
use Test::More tests => 95; |
7 |
|
|
8 |
use lib 'lib'; |
use lib 'lib'; |
9 |
|
|
15 |
|
|
16 |
ok( $o->ping, 'ping' ); |
ok( $o->ping, 'ping' ); |
17 |
|
|
18 |
|
diag "Commands operating on string values"; |
19 |
|
|
20 |
ok( $o->set( foo => 'bar' ), 'set foo => bar' ); |
ok( $o->set( foo => 'bar' ), 'set foo => bar' ); |
21 |
|
|
22 |
eval { $o->set( foo => 'bar', 1 ) }; |
eval { $o->set( foo => 'bar', 1 ) }; |
45 |
|
|
46 |
ok( $o->set('key-left' => $key_next), 'key-left' ); |
ok( $o->set('key-left' => $key_next), 'key-left' ); |
47 |
|
|
48 |
|
is_deeply( [ $o->mget( 'foo', 'key-next', 'key-left' ) ], [ 'baz', 0, 3 ], 'mget' ); |
49 |
|
|
50 |
my @keys; |
my @keys; |
51 |
|
|
52 |
foreach ( 0 .. $key_next ) { |
foreach ( 0 .. $key_next ) { |
119 |
|
|
120 |
ok( ! $o->rpop( $list ), 'rpop' ); |
ok( ! $o->rpop( $list ), 'rpop' ); |
121 |
|
|
122 |
# Commands operating on sets |
|
123 |
|
diag "Commands operating on sets"; |
124 |
|
|
125 |
my $set = 'test-set'; |
my $set = 'test-set'; |
126 |
$o->del($set); |
$o->del($set); |
128 |
ok( $o->sadd( $set, 'foo' ), 'sadd' ); |
ok( $o->sadd( $set, 'foo' ), 'sadd' ); |
129 |
ok( ! $o->sadd( $set, 'foo' ), 'sadd' ); |
ok( ! $o->sadd( $set, 'foo' ), 'sadd' ); |
130 |
cmp_ok( $o->scard( $set ), '==', 1, 'scard' ); |
cmp_ok( $o->scard( $set ), '==', 1, 'scard' ); |
131 |
|
ok( $o->sismember( $set, 'foo' ), 'sismember' ); |
132 |
|
|
133 |
cmp_ok( $o->type( $set ), 'eq', 'set', 'type is set' ); |
cmp_ok( $o->type( $set ), 'eq', 'set', 'type is set' ); |
134 |
|
|
136 |
ok( ! $o->srem( $set, 'foo' ), 'srem again' ); |
ok( ! $o->srem( $set, 'foo' ), 'srem again' ); |
137 |
cmp_ok( $o->scard( $set ), '==', 0, 'scard' ); |
cmp_ok( $o->scard( $set ), '==', 0, 'scard' ); |
138 |
|
|
139 |
|
$o->sadd( 'test-set1', $_ ) foreach ( 'foo', 'bar', 'baz' ); |
140 |
|
$o->sadd( 'test-set2', $_ ) foreach ( 'foo', 'baz', 'xxx' ); |
141 |
|
|
142 |
|
my $inter = [ 'baz', 'foo' ]; |
143 |
|
|
144 |
|
is_deeply( [ $o->sinter( 'test-set1', 'test-set2' ) ], $inter, 'siter' ); |
145 |
|
|
146 |
|
ok( $o->sinterstore( 'test-set-inter', 'test-set1', 'test-set2' ), 'sinterstore' ); |
147 |
|
|
148 |
|
cmp_ok( $o->scard( 'test-set-inter' ), '==', $#$inter + 1, 'cardinality of intersection' ); |
149 |
|
|
150 |
|
|
151 |
|
diag "Multiple databases handling commands"; |
152 |
|
|
153 |
|
ok( $o->select( 1 ), 'select' ); |
154 |
|
ok( $o->select( 0 ), 'select' ); |
155 |
|
|
156 |
|
ok( $o->move( 'foo', 1 ), 'move' ); |
157 |
|
ok( ! $o->exists( 'foo' ), 'gone' ); |
158 |
|
|
159 |
|
ok( $o->select( 1 ), 'select' ); |
160 |
|
ok( $o->exists( 'foo' ), 'exists' ); |
161 |
|
|
162 |
|
ok( $o->flushdb, 'flushdb' ); |
163 |
|
cmp_ok( $o->dbsize, '==', 0, 'empty' ); |
164 |
|
|
165 |
|
diag "Connection handling"; |
166 |
|
|
167 |
ok( $o->quit, 'quit' ); |
ok( $o->quit, 'quit' ); |