]> git.saurik.com Git - redis.git/blob - client-libraries/php/tests.php
Merge git://github.com/ludoo/redis
[redis.git] / client-libraries / php / tests.php
1 <?php
2
3 // poor man's tests
4
5 require_once('redis.php');
6
7 $r =& new Redis('localhost');
8 $r->connect();
9 $r->select_db(9);
10 $r->flush();
11 echo $r->ping() . "\n";
12 echo $r->do_echo('ECHO test') . "\n";
13 echo "SET aaa " . $r->set('aaa', 'bbb') . "\n";
14 echo "SETNX aaa " . $r->set('aaa', 'ccc', true) . "\n";
15 echo "GET aaa " . $r->get('aaa') . "\n";
16 echo "INCR aaa " . $r->incr('aaa') . "\n";
17 echo "GET aaa " . $r->get('aaa') . "\n";
18 echo "INCRBY aaa 3 " . $r->incr('aaa', 2) . "\n";
19 echo "GET aaa " . $r->get('aaa') . "\n";
20 echo "DECR aaa " . $r->decr('aaa') . "\n";
21 echo "GET aaa " . $r->get('aaa') . "\n";
22 echo "DECRBY aaa 2 " . $r->decr('aaa', 2) . "\n";
23 echo "GET aaa " . $r->get('aaa') . "\n";
24 echo "EXISTS aaa " . $r->exists('aaa') . "\n";
25 echo "EXISTS fsfjslfjkls " . $r->exists('fsfjslfjkls') . "\n";
26 echo "DELETE aaa " . $r->delete('aaa') . "\n";
27 echo "EXISTS aaa " . $r->exists('aaa') . "\n";
28 echo 'SET a1 a2 a3' . $r->set('a1', 'a') . $r->set('a2', 'b') . $r->set('a3', 'c') . "\n";
29 echo 'KEYS a* ' . print_r($r->keys('a*'), true) . "\n";
30 echo 'RANDOMKEY ' . $r->randomkey('a*') . "\n";
31 echo 'RENAME a1 a0 ' . $r->rename('a1', 'a0') . "\n";
32 echo 'RENAMENX a0 a2 ' . $r->rename('a0', 'a2', true) . "\n";
33 echo 'RENAMENX a0 a1 ' . $r->rename('a0', 'a1', true) . "\n";
34
35 echo 'LPUSH a0 aaa ' . $r->push('a0', 'aaa') . "\n";
36 echo 'LPUSH a0 bbb ' . $r->push('a0', 'bbb') . "\n";
37 echo 'RPUSH a0 ccc ' . $r->push('a0', 'ccc', false) . "\n";
38 echo 'LLEN a0 ' . $r->llen('a0') . "\n";
39 echo 'LRANGE sdkjhfskdjfh 0 100 ' . print_r($r->lrange('sdkjhfskdjfh', 0, 100), true) . "\n";
40 echo 'LRANGE a0 0 0 ' . print_r($r->lrange('sdkjhfskdjfh', 0, 0), true) . "\n";
41 echo 'LRANGE a0 0 100 ' . print_r($r->lrange('a0', 0, 100), true) . "\n";
42 echo 'LTRIM a0 0 1 ' . $r->ltrim('a0', 0, 1) . "\n";
43 echo 'LRANGE a0 0 100 ' . print_r($r->lrange('a0', 0, 100), true) . "\n";
44 echo 'LINDEX a0 0 ' . $r->lindex('a0', 0) . "\n";
45 echo 'LPUSH a0 bbb ' . $r->push('a0', 'bbb') . "\n";
46 echo 'LRANGE a0 0 100 ' . print_r($r->lrange('a0', 0, 100), true) . "\n";
47 echo 'RPOP a0 ' . $r->pop('a0') . "\n";
48 echo 'LPOP a0 ' . $r->pop('a0', false) . "\n";
49 echo 'LSET a0 ccc 0 ' . $r->lset('a0', 'ccc', 0) . "\n";
50 echo 'LRANGE a0 0 100 ' . print_r($r->lrange('a0', 0, 100), true) . "\n";
51
52 echo 'SADD s0 aaa ' . $r->sadd('s0', 'aaa') . "\n";
53 echo 'SADD s0 aaa ' . $r->sadd('s0', 'aaa') . "\n";
54 echo 'SADD s0 bbb ' . $r->sadd('s0', 'bbb') . "\n";
55 echo 'SREM s0 bbb ' . $r->srem('s0', 'bbb') . "\n";
56 echo 'SISMEMBER s0 aaa ' . $r->sismember('s0', 'aaa') . "\n";
57 echo 'SISMEMBER s0 bbb ' . $r->sismember('s0', 'bbb') . "\n";
58 echo 'SADD s0 bbb ' . $r->sadd('s0', 'bbb') . "\n";
59 echo 'SADD s1 bbb ' . $r->sadd('s1', 'bbb') . "\n";
60 echo 'SADD s1 aaa ' . $r->sadd('s1', 'aaa') . "\n";
61 echo 'SINTER s0 s1 ' . print_r($r->sinter(array('s0', 's1')), true) . "\n";
62 echo 'SREM s0 bbb ' . $r->srem('s0', 'bbb') . "\n";
63 echo 'SINTER s0 s1 ' . print_r($r->sinter(array('s0', 's1')), true) . "\n";
64 echo 'SMEMBERS s1 ' . print_r($r->smembers('s1'), true) . "\n";
65
66 echo 'SELECT 8 ' . $r->select_db(8) . "\n";
67 echo 'EXISTS s1 ' . $r->exists('s1') . "\n";
68 if ($r->exists('s1'))
69 echo 'SMEMBERS s1 ' . print_r($r->smembers('s1'), true) . "\n";
70 echo 'SELECT 9 ' . $r->select_db(9) . "\n";
71 echo 'SMEMBERS s1 ' . print_r($r->smembers('s1'), true) . "\n";
72 echo 'MOVE s1 8 ' . $r->move('s1', 8) . "\n";
73 echo 'EXISTS s1 ' . $r->exists('s1') . "\n";
74 if ($r->exists('s1'))
75 echo 'SMEMBERS s1 ' . print_r($r->smembers('s1'), true) . "\n";
76 echo 'SELECT 8 ' . $r->select_db(8) . "\n";
77 echo 'SMEMBERS s1 ' . print_r($r->smembers('s1'), true) . "\n";
78 echo 'SELECT 9 ' . $r->select_db(9) . "\n";
79
80 echo 'SAVE ' . $r->save() . "\n";
81 echo 'BGSAVE ' . $r->save(true) . "\n";
82 echo 'LASTSAVE ' . $r->lastsave() . "\n";
83
84 echo 'INFO ' . print_r($r->info()) . "\n";
85
86 ?>