扩展安装
yum install php-devel//通过yum命令安装php开发扩展包
具体步骤
- 下载phpredis扩展http://github.com/phpredis/phpredis/archive/develop.zip
- 解压unzip develop.zip
- phpize
- ./configure --with-php-config=/usr/bin/php-config
- make / make install
- php.ini --extension=redis.so
php --ini查看php配置文件在哪
代码部分
- string的操作
$redis = new \Redis();//gen mulu
$redis->connect('127.0.0.1',6379);
$redis->delete("string1");
$redis->set("string1","val1");
$val = $redis->get("string1");
var_dump($val);
$redis->set("string1",4);
$redis->incr("string1",2);
echo $redis->get("string1");
- List的操作
$redis = new \Redis();//gen mulu
$redis->connect('127.0.0.1',6379);
$redis->delete("list1");
$redis->lPush("list1","A");
$redis->lPush("list1","B");
$redis->lPush("list1","C");
$val = $redis->rPop("list1");
var_dump($val);
- Set类型的操作
$redis = new \Redis();//gen mulu
$redis->connect('127.0.0.1',6379);
$redis->delete("set1");
$redis->sAdd('set1',"A");
$redis->sAdd('set1','B');
$redis->sAdd('set1','C');
$redis->sAdd('set1','C');
$val = $redis->sCard("set1");
var_dump($val);
$val = $redis->sMembers("set1");
var_dump($val);
- hash类型操作
$redis = new \Redis();//gen mulu
$redis->connect('127.0.0.1',6379);
$redis->delete("hash1");
$redis->hSet('driver1','name','mingming');
$redis->hSet('driver1','age','25');
$redis->hSet('driver1','gender',1);
$val = $redis->hGet('driver1','name');
var_dump($val);
$val = $redis->hMGet('driver1',array('name','age'));
var_dump($val);
- sort set类型
$redis = new \Redis();//gen mulu
$redis->connect('127.0.0.1',6379);
$redis->delete("zset1");
$redis->zAdd('zset1',100,'xiaoming');
$redis->zAdd('zset1',90,'xiaohong');
$redis->zAdd('zset1',93,'xiaowang');
$val = $redis->zRange('zset1',0,-1);
var_dump($val);
$val = $redis->zRevRange('zset1',0,-1);
var_dump($val);