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