$redis = new redis();
$result = $redis->connect|('127.0.0.1',6379); //connect:实例连接到redis
$result = $redis->set('hello','123456'); //set:设置key和value的值
$result = $redis->get('hello'); //get:获取指定的键的值
$result = $redis->delete('hello'); //delete:删除指定的键的值
$result = $redis->setnx('hello','654321'); //setnx:如果键(hello)的值存在,则返回123456,如果键(hello)不存在,则返回654321
$result = $redis->exists('hello'); //exists:验证指定的键是否存在
$result = $redis->incr('hello'); //incr:数字递增键的值,如:124567
$result = $redis->decr('hello'); //decr:数字递减键的值,如:123455
$result = $redis->getMultiple(array('hello')); //getMultiple:取得所有指定键的值
var_dump($redis->lpush("test","111")); 结果:int(1)
var_dump($redis->lpush("test","222")); 结果:int(2) //lpush:在队列(test)头部添加字符串,没有次列表则创建,有但不是列表返回false,成功返回数组长度
var_dump($redis->lpush("test","111")); 结果:int(1)
var_dump($redis->lpush("test","222")); 结果:int(2)
var_dump($redis->rpush("test","333")); 结果:int(3)
var_dump($redis->rpush("test","444")); 结果:int(4) //rpush:在队列(test)尾部添加字符串,没有次列表则创建,有但不是列表返回false,成功返回数组长度
$result = $redis->lpop('test'); //lpop:返回和移除列表的第一个元素
$redis->lsize('test'); => $redis->llen('test'); //lsize、llen:返回的列表的长度。如果列表不存在或为空,该命令返回0。如果该键不是列表,该命令返回false
$result = $redis->lget('test',2); //lget:返回指定键存储的列表的指定的元素的值
$result = $redis->lset('test',2,'123456'); //lset:为列表指定的索引赋新的值,若不存在该索引返回false
$result = $redis->lgetrange('test',0,2); //lgetrange:返回在该区域中的指定键列表中开始到结束存储的指定元素,lGetRange(key, start, end)。0第一个元素,1第二个元素… -1最后一个元素,-2的倒数第二…
$redis->lpush('test','a');
$redis->lpush('test','b');
$redis->lpush('test','c');
$redis->rpush('test','a');
print_r($redis->lgetrange('test', 0, -1)); 结果:Array ( [0] => c [1] => b [2] => a [3] => a )
var_dump($redis->lremove('test','a',2)); 结果:int(2)
print_r($redis->lgetrange('test', 0, -1)); 结果:Array ( [0] => c [1] => b ) //lremove:从列表中从头部开始移除count个匹配的值。如果count为零,所有匹配的元素都被删除。如果count是负数,内容从尾部开始删除
var_dump($redis->sadd('test','111')); 结果:bool(true)
var_dump($redis->sadd('test','333')); 结果:bool(true)
print_r($redis->sort('test')); 结果:Array ( [0] => 111 [1] => 333 ) //sadd:为一个key添加一个值。如果这个值已经在这个key中,则返回false
$redis->sadd('test','111');
$redis->sadd('test','333');
$redis->sremove('test','111');
print_r($redis->sort('test')); 结果:Array ( [0] => 333 ) //sremove:删除key中指定的value值
$redis->sadd('test','111');
$redis->sadd('test','333');
$redis->sadd('test1','222');
$redis->sadd('test1','444');
$redis->smove('test',"test1",'111');
print_r($redis->sort('test1')); 结果:Array ( [0] => 111 [1] => 222 [2] => 444 ) //smove:将Key1中的value移动到Key2中
$redis->sadd('test','111');
$redis->sadd('test','112');
$redis->sadd('test','113');
var_dump($redis->scontains('test', '111')); 结果:bool(true) //scontains:检查集合中是否存在指定的值
$redis->sadd('test','111');
$redis->sadd('test','112');
echo $redis->ssize('test'); 结果:2 //ssize:返回集合中存储值的数量
$redis->sadd("test","111");
$redis->sadd("test","222");
$redis->sadd("test","333");
var_dump($redis->spop("test")); 结果:string(3) "333" //spop:随机移除并返回key中的一个值
$redis->sadd("test","111");
$redis->sadd("test","222");
$redis->sadd("test","333");
$redis->sadd("test1","111");
$redis->sadd("test1","444");
var_dump($redis->sinter("test","test1")); //结果:array(1) { [0]=> string(3) "111" } //sinter:返回一个所有指定键的交集。如果只指定一个键,那么这个命令生成这个集合的成员。如果不存在某个键,则返回false
$redis->sadd("test","111");
$redis->sadd("test","222");
$redis->sadd("test","333");
$redis->sadd("test1","111");
$redis->sadd("test1","444");
var_dump($redis->sinterstore('new',"test","test1")); 结果:int(1)
var_dump($redis->smembers('new')); 结果:array(1) { [0]=> string(3) "111" } //sinterstore:执行sInter命令并把结果储存到新建的变量中
$redis->sadd("test","111");
$redis->sadd("test","222");
$redis->sadd("test","333");
$redis->sadd("test1","111");
$redis->sadd("test1","444");
print_r($redis->sunion("test","test1")); 结果:Array ( [0] => 111 [1] => 222 [2] => 333 [3] => 444 ) //sunion:返回一个所有指定键的并集
$redis->sadd("test","111");
$redis->sadd("test","222");
$redis->sadd("test","333");
$redis->sadd("test1","111");
$redis->sadd("test1","444");
var_dump($redis->sunionstore('new',"test","test1")); //结果:int(4)
print_r($redis->smembers('new')); //结果:Array ( [0] => 111 [1] => 222 [2] => 333 [3] => 444 ) //sunionstore:执行sunion命令并把结果储存到新建的变量中
$redis->sadd("test","111");
$redis->sadd("test","222");
$redis->sadd("test","333");
$redis->sadd("test1","111");
$redis->sadd("test1","444");
print_r($redis->sdiff("test","test1")); //结果:Array ( [0] => 222 [1] => 333 ) //sdiff:返回第一个集合中存在并在其他所有集合中不存在的结果
$redis->sadd("test","111");
$redis->sadd("test","222");
$redis->sadd("test","333");
$redis->sadd("test1","111");
$redis->sadd("test1","444");
var_dump($redis->sdiffstore('new',"test","test1")); //结果:int(2)
print_r($redis->smembers('new')); //结果:Array ( [0] => 222 [1] => 333 ) //sdiffstore:执行sdiff命令并把结果储存到新建的变量中
$redis->sadd("test","111");
$redis->sadd("test","222");
print_r($redis->smembers('test')); //结果:Array ( [0] => 111 [1] => 222 ) //smembers, sgetmembers:返回集合的内容
?>