3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
use Test::More tests => 62; |
use Test::More tests => 103; |
7 |
|
|
8 |
use lib 'lib'; |
use lib 'lib'; |
9 |
|
|
15 |
|
|
16 |
ok( $o->ping, 'ping' ); |
ok( $o->ping, 'ping' ); |
17 |
|
|
18 |
|
|
19 |
|
diag "Commands operating on string values"; |
20 |
|
|
21 |
ok( $o->set( foo => 'bar' ), 'set foo => bar' ); |
ok( $o->set( foo => 'bar' ), 'set foo => bar' ); |
22 |
|
|
23 |
eval { $o->set( foo => 'bar', 1 ) }; |
eval { $o->set( foo => 'bar', 1 ) }; |
29 |
|
|
30 |
cmp_ok( $o->get( 'foo' ), 'eq', 'baz', 'get foo = baz' ); |
cmp_ok( $o->get( 'foo' ), 'eq', 'baz', 'get foo = baz' ); |
31 |
|
|
32 |
|
ok( $o->set( 'test-undef' => 42 ), 'set test-undef' ); |
33 |
|
ok( $o->set( 'test-undef' => undef ), 'set undef' ); |
34 |
|
ok( ! defined $o->get( 'test-undef' ), 'get undef' ); |
35 |
|
diag $o->exists( 'test-undef' ); |
36 |
|
ok( $o->exists( 'test-undef' ), 'exists undef' ); |
37 |
|
|
38 |
$o->del('non-existant'); |
$o->del('non-existant'); |
39 |
|
|
40 |
ok( ! $o->exists( 'non-existant' ), 'exists non-existant' ); |
ok( ! $o->exists( 'non-existant' ), 'exists non-existant' ); |
46 |
|
|
47 |
ok( $o->set('key-left' => $key_next), 'key-left' ); |
ok( $o->set('key-left' => $key_next), 'key-left' ); |
48 |
|
|
49 |
|
is_deeply( [ $o->mget( 'foo', 'key-next', 'key-left' ) ], [ 'baz', 0, 3 ], 'mget' ); |
50 |
|
|
51 |
my @keys; |
my @keys; |
52 |
|
|
53 |
foreach ( 0 .. $key_next ) { |
foreach ( 0 .. $key_next ) { |
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 |
|
|
98 |
|
|
99 |
ok( $o->lpush( $list => "l$_" ), 'lpush' ) foreach ( 1 .. 2 ); |
ok( $o->lpush( $list => "l$_" ), 'lpush' ) foreach ( 1 .. 2 ); |
100 |
|
|
101 |
|
cmp_ok( $o->type($list), 'eq', 'list', 'type' ); |
102 |
cmp_ok( $o->llen($list), '==', 5, 'llen' ); |
cmp_ok( $o->llen($list), '==', 5, 'llen' ); |
103 |
|
|
104 |
is_deeply( [ $o->lrange( $list, 0, 1 ) ], [ 'l2', 'l1' ], 'lrange' ); |
is_deeply( [ $o->lrange( $list, 0, 1 ) ], [ 'l2', 'l1' ], 'lrange' ); |
105 |
|
|
106 |
ok( $o->ltrim( $list, 2, 3 ), 'ltrim' ); |
ok( $o->ltrim( $list, 1, 2 ), 'ltrim' ); |
107 |
cmp_ok( $o->llen($list), '==', 2, 'llen after ltrim' ); |
cmp_ok( $o->llen($list), '==', 2, 'llen after ltrim' ); |
108 |
|
|
109 |
|
cmp_ok( $o->lindex( $list, 0 ), 'eq', 'l1', 'lindex' ); |
110 |
|
cmp_ok( $o->lindex( $list, 1 ), 'eq', 'r1', 'lindex' ); |
111 |
|
|
112 |
|
ok( $o->lset( $list, 0, 'foo' ), 'lset' ); |
113 |
|
cmp_ok( $o->lindex( $list, 0 ), 'eq', 'foo', 'verified' ); |
114 |
|
|
115 |
|
ok( $o->lrem( $list, 1, 'foo' ), 'lrem' ); |
116 |
|
cmp_ok( $o->llen( $list ), '==', 1, 'llen after lrem' ); |
117 |
|
|
118 |
|
cmp_ok( $o->lpop( $list ), 'eq', 'r1', 'lpop' ); |
119 |
|
|
120 |
|
ok( ! $o->rpop( $list ), 'rpop' ); |
121 |
|
|
122 |
|
|
123 |
|
diag "Commands operating on sets"; |
124 |
|
|
125 |
|
my $set = 'test-set'; |
126 |
|
$o->del($set); |
127 |
|
|
128 |
|
ok( $o->sadd( $set, 'foo' ), 'sadd' ); |
129 |
|
ok( ! $o->sadd( $set, 'foo' ), 'sadd' ); |
130 |
|
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' ); |
134 |
|
|
135 |
|
ok( $o->srem( $set, 'foo' ), 'srem' ); |
136 |
|
ok( ! $o->srem( $set, 'foo' ), 'srem again' ); |
137 |
|
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 |
|
|
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 |
|
|
179 |
|
|
180 |
|
diag "Connection handling"; |
181 |
|
|
182 |
ok( $o->quit, 'quit' ); |
ok( $o->quit, 'quit' ); |