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
| $redis = new redis(); $redis->connect('127.0.0.1', '6379') || die("连接失败!"); $redis->auth("admin"); $redis->set('test', 200); $redis->mset(array('key0' => 'value0', 'key1' => 'value1')); $redis->mget(array('key0', 'key1', 'key2')); $redis->setnx('key',value); $redis->msetnx(array('key0' => 'value0', 'key1' => 'value1')); $redis->getset("key",'newvalue'); $redis->setex('key',10,'value10'); $redis->setrange('key',0,'hello'); $redis->getrange("key",0,2); $redis->ttl('key'); $redis->keys("*a*"); $redis->get("test"); $redis->getMultiple(array('key1', 'key2', 'key3')); $exits = $redis->exists('test'); echo $exists?$res2:"null"; echo $res1?$res2:"null";die; $redis->delete('key1', 'key2'); $redis->delete(array('key3', 'key4', 'key5')); $redis->delete( $redis->keys("*")); $redis->incr("key",1); $redis->incrBy('key',10); $redis->decr("key",10); $redis->decrBy('key',10); $redis->append("key","appendvalue"); $redis->strlen('key'); $redis->flushall();die; $redis->flushdb();die;
$redis->hset("test","username","admin"); $redis->hget("test","username"); $redis->hsetnx("test","username","[email protected]"); $redis->hmset("testabc",array("a"=>1,"b"=>2,"c"=>3,'d'=>4)); $redis->hmget("testabc",array("a","b","c")); $redis->hincrBy("test","password","123456"); $redis->hexists("test","usernames"); $redis->hlen("test"); $redis->hdel("test","key"); $redis->hkeys("test"); $redis->hvals("test"); $redis->hgetall("test"); $redis->lrange("list",0,-1); $redis->lpush("list","1"); $redis->rpush("list","test"); $redis->lpop("list"); $redis->rpop("list"); echo $redis->lrem("list",2,'key'); $redis->lset("list",-1,"啊"); $redis->lindex("list",0); $redis->llen("list"); $redis->ltrim("list",0,1); $redis->linsert("list"); $redis->rpoplpush("list","listt"); $redis->sadd("col","a","b","c"); $redis->smembers("col"); $redis->srem("col",'d'); $redis->spop("col"); $redis->sdiff("set1","set2"); $redis->sdiffstore("dif","set1","set2"); $redis->sinter("set","set1",'set2'); $res = $redis->sinterstore("inter","set","set1"); $redis->sunion("set","set1",'set2'); $redis->sunionstore("union","set","set1"); $redis->smove("set1","set2","value"); $redis->scard("set"); $redis->sismember("set","value"); $redis->srandmember("set");
$redis->keys("*"); $redis->keys("*t"); $res = $redis->keys("*"); foreach ($res as $k => $v) { echo $v."=>".$redis->get($v)."<br>"; } $redis->exists("set"); $redis->del("inter"); $redis->expire("set2",100); $redis->ttl("set3");
$redis->select("1"); $redis->set("name","test"); $redis->get("name"); $redis->move("get",1); $redis->persist("set2"); $redis->randomkey(); $redis->rename("names","newname"); $redis->type("zset"); $redis->dbsize(); $redis->info(); $redis->echo("hello,world");
$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); print_R($res);die;
$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) { $ress[] = $redis->hgetall("blog:user:" . $v); } echo"<pre>"; print_r($ress);
|