实例连接到一个Redis。
$redis = new redis(); $result = $redis->connect('127.0.0.1', 6379); var_dump($result); //结果:bool(true)
<?php $redis = new redis(); $redis->connect('127.0.0.1', 6379); $result = $redis->get('test'); var_dump($result);
?>
<?php $redis = new redis(); $redis->connect('127.0.0.1', 6379); $result = $redis->get('test'); var_dump($result);
?>
<?php $redis = new redis(); $redis->connect('127.0.0.1', 6379); $redis->set('test',"yyd"); echo $redis->get('test');
$redis->delete('test'); var_dump($redis->get('test')); //结果:bool(false) ?>
<?php $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 ?>
<?php $redis = new redis(); $redis->connect('127.0.0.1', 6379); $redis->set('test',"1111111111111"); var_dump($redis->exists('test')); //结果:bool(true) ?>
<?php $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) ?>
<?php $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) ?>
<?php $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 ) ?>
<?php $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) ?>
<?php $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) ?>
<?php $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" ?>
<?php $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->rpop("test")); //结果:string(3) "444" ?>
<?php $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) ?>
<?php $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" ?>
<?php $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" ?>
<?php $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 ) ?>
<?php $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 ) ?>