1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| <?php
$redis = new redis(); $redis->connect('127.0.01', '6379') || die('Connect failed'); $redis->auth('admin');
$redis->keys('*'); $redis->keys('s*'); $redis->exists('key'); $redis->del('key'); $redis->expire('key', 3600); $redis->ttl('key'); $redis->select('db_index'); $redis->set('key', 'val'); $redis->get('key'); $redis->move('key', 'db_index_2'); $redis->persist('key'); $redis->randomKey(); $redis->type('key'); $redis->dbSize(); $redis->info(); $redis->echo('hello world');
$redis->set('test', 1024); $redis->mset(array('key0'=>'val0','key1'=>'val1')); $redis->mget(array('key0', 'key1')); $redis->setnx('key', 'val'); $redis->msetnx(array('key0' => 'val0', 'key1' => 'val1')); $redis->getSet('key', 'new_val'); $redis->setex('key', 10, 'val10'); $redis->setRange('key', 0, 'hello'); $redis->getRange('key', 0, 2); $redis->ttl('key'); $redis->keys('*a*'); $redis->get('key'); $redis->getMultiple(array('key1', 'key2', 'key3')); $exits = $redis->exists('key'); $redis->delete('key1', 'key2'); $redis->delete(array('key3', 'key4', 'key5')); $redis->delete($redis->keys('*')); $redis->incr('key'); $redis->incrBy('key', 10); $redis->decr('key'); $redis->decrBy('key', 10); $redis->append('key', 'append_val'); $redis->strlen('key');
$redis->flushAll(); $redis->flushDB();
$redis->hSet('key', 'hash_key', 'val'); $redis->hGet('key','hash_key'); $redis->hSetNx('key', 'hash_key', 'val'); $redis->hMset('key', array('a'=>1, 'b'=>2, 'c'=>3)); $redis->hMGet('key', array('a','b','c')); $redis->hIncrBy('key', 'hash_key', 'val'); $redis->hExists('key', 'hash_key'); $redis->hLen('key'); $redis->hDel('key', 'hash_key'); $redis->hKeys('key'); $redis->hVals('key'); $redis->hGetAll('key');
$redis->lRange('key', 'start', 'end'); $redis->lPush('key', 'val'); $redis->rPush('key', 'val'); $redis->lPop('key'); $redis->rPop('key'); $redis->lRem('key', 'val', 'n'); $redis->lSet('key', '-1', 'val'); $redis->lIndex('key', 0); $redis->lLen('key'); $redis->lTrim('key', 'start_0', 'end_-1'); $redis->lInsert('key', 'position', 'pivot', 'val'); $redis->rpoplpush('srcKey', 'dstKey');
$redis->sAdd('key', 'val1', 'val2'); $redis->sMembers('key'); $redis->sRem('key', 'member1', 'member2'); $redis->sPop('key'); $redis->sDiff('key1', 'key2'); $redis->sDiffStore('dstKey', 'key1', 'key2'); $redis->sInter('key1', 'key2'); $redis->sInterStore('dstKey', 'key1', 'key2'); $redis->sUnion('key1', 'key2'); $redis->sUnionStore('dstKey', 'key1', 'key2'); $redis->sMove('srcKey', 'dstKey', 'member'); $redis->sCard('key'); $redis->sIsMember('key', 'val'); $redis->sRandMember('key', 'count_num');
$uid = $redis->incr('blog:id'); $res = $redis->hMset('blog:user:' . $uid, array('id' => $uid, 'username' =>'admin'.time() . time(), 'password' => md5(time()))); $redis->rPush('blog:uid', $uid);
$res = $redis->hGetAll('blog:user:' . $uid); $redis->del('blog:user:' . $uid); $redis->lRem('blog:uid', $uid, 'count');
$count = $redis->lSize('blog:uid'); $page_size = 3; $page_num = !empty($_GET['page']) ? $_GET['page'] : 1; $page_count = ceil($count / $page_size); $ids = $redis->lrange("blog:uid", ($page_num - 1) * $page_size, (($page_num - 1) * $page_size + $page_size - 1));
foreach ($ids as $v) { $result[] = $redis->hgetall("blog:user:" . $v); } echo"<pre>"; print_r($result);
|