1,connect
描述:实例连接到一个Redis.
参数:host: string,port: int
返回值:BOOL 成功返回:TRUE;失败返回:FALSE
示例:
$redis = new redis();
$result = $redis->connect('127.0.0.1', 6379);
var_dump($result); //结果:bool(true)
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$result = $redis->set('test',"11111111111");
var_dump($result); //结果:bool(true)
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$result = $redis->get('test');
var_dump($result); //结果:string(11) "11111111111"
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('test',"1111111111111");
echo $redis->get('test'); //结果:1111111111111
$redis->delete('test');
var_dump($redis->get('test')); //结果:bool(false)
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('test',"1111111111111");
$redis->setnx('test',"22222222");
echo $redis->get('test'); //结果:1111111111111
$redis->delete('test');
$redis->setnx('test',"22222222");
echo $redis->get('test'); //结果:22222222
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('test',"1111111111111");
var_dump($redis->exists('test')); //结果:bool(true)
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('test',"123");
var_dump($redis->incr("test")); //结果:int(124)
var_dump($redis->incr("test")); //结果:int(125)
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('test',"123");
var_dump($redis->decr("test")); //结果:int(122)
var_dump($redis->decr("test")); //结果:int(121)
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('test1',"1");
$redis->set('test2',"2");
$result = $redis->getMultiple(array('test1','test2'));
print_r($result); //结果:Array ( [0] => 1 [1] => 2 )
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
var_dump($redis->lpush("test","111")); //结果:int(1)
var_dump($redis->lpush("test","222")); //结果:int(2)
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
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)
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->lpush("test","111");
$redis->lpush("test","222");
$redis->rpush("test","333");
$redis->rpush("test","444");
var_dump($redis->lpop("test")); //结果:string(3) "222"
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->lpush("test","111");
$redis->lpush("test","222");
$redis->rpush("test","333");
$redis->rpush("test","444");
var_dump($redis->lsize("test")); //结果:int(4)
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->lpush("test","111");
$redis->lpush("test","222");
$redis->rpush("test","333");
$redis->rpush("test","444");
var_dump($redis->lget("test",3)); //结果:string(3) "444"
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->lpush("test","111");
$redis->lpush("test","222");
var_dump($redis->lget("test",1)); //结果:string(3) "111"
var_dump($redis->lset("test",1,"333")); //结果:bool(true)
var_dump($redis->lget("test",1)); //结果:string(3) "333"
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->lpush("test","111");
$redis->lpush("test","222");
print_r($redis->lgetrange("test",0,-1)); //结果:Array ( [0] => 222 [1] => 111 )
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$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 )
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
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 )
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->sadd('test','111');
$redis->sadd('test','333');
$redis->sremove('test','111');
print_r($redis->sort('test')); //结果:Array ( [0] => 333 )
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->delete('test1');
$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 )
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->sadd('test','111');
$redis->sadd('test','112');
$redis->sadd('test','113');
var_dump($redis->scontains('test', '111')); //结果:bool(true)
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->sadd('test','111');
$redis->sadd('test','112');
echo $redis->ssize('test'); //结果:2
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->sadd("test","111");
$redis->sadd("test","222");
$redis->sadd("test","333");
var_dump($redis->spop("test")); //结果:string(3) "333"
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$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" }
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$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" }
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$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 )
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$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(4)
print_r($redis->smembers('new')); //结果:Array ( [0] => 111 [1] => 222 [2] => 333 [3] => 444 )
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$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 )
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$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 )
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->sadd("test","111");
$redis->sadd("test","222");
print_r($redis->smembers('test')); //结果:Array ( [0] => 111 [1] => 222 )
?>
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->close()
?>